当前位置:   article > 正文

Codeforces Round #704 (Div. 2) 题解

codeforces round #704 (div. 2)

Codeforces Round #704 (Div. 2)

A. Three swimmers
int main()
{
	ios;
	int t;
	cin >> t;
	while (t--)
	{
		ll p,a,b,c;
		cin >> p >> a >> b >> c;
		ll t1=p/a+(p%a==0?0:1);
		ll t2=p/b+(p%b==0?0:1);
		ll t3=p/c+(p%c==0?0:1);
		t1=t1*a-p;
		t2=t2*b-p;
		t3=t3*c-p;
		cout << min(t1,min(t2,t3)) << endl;
	}
}
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18

B. Card Deck
int p[maxn];
map<int,int> book;
int main()
{
	ios;
	int t;
	cin >> t;
	while (t--)
	{
		book.clear();
		int n;
		cin >> n;
		int maxx=-1;
		for(int i=1;i<=n;i++)
		{
			cin >> p[i];
			book[p[i]]=i;
		}
		int pre=n+1,num=0;
		for(int i=n;i>=1;i--)
		{
			if(book[i]>pre) continue;
			for(int j=book[i];j<pre;j++) cout << p[j] << ' ';
			num+=pre-book[i];
			if(num==n) break;
			pre=book[i];
		}
		cout << endl;
	}
}
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30

C. Maximum width

正向和逆向都找一遍,取第一个符合条件的字符串,做差找最大值即可。

char s[maxn],t[maxn];
int p1[maxn],p2[maxn];
int m,n;
void solve()
{
	for(int i=1,j=1;i<=n && j<=m;i++)
		if(s[i]==t[j]) p1[j++]=i;
	for(int i=n,j=m;i>=1 && j>=1;i--)
		if(s[i]==t[j]) p2[j--]=i;
	int ans=1;
	for(int i=2;i<=m;i++)
		ans=max(ans,p2[i]-p1[i-1]);
	cout << ans << endl;
}
int main()
{
	cin >> n >> m;
	scanf("%s%s",s+1,t+1);
	int pos=1;
	solve();
}
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21

D. Genius’s Gambit

构造,10-01=01,100-001=011,这样我们可以构造任意数量的1。
根据这个去模拟构造即可。

int main() {
    ios;
    int a,b,k,aa,bb;
    cin >> a >> b >> k;
    aa=a,bb=b;
    if(b==1)
    {
        if(k==0)
        {
            cout << "YES" << endl;
            cout << 1;
            for(int i=1;i<a+b;i++) cout << 0;
            cout << endl;
            cout << 1;
            for(int i=1;i<a+b;i++) cout << 0;
            cout << endl;
        }
        else cout << "NO" << endl;
    }
    else if(k>a+b-2) cout << "NO" << endl;
    else
    {
        string s1="",s2="";
        if(k!=0)
        {
            s1="11";
            s2="10";
            b-=2;
            for(int i=1;i<k;i++)
            {
                if(a>1)
                {
                    a--;
                    s1+="0";
                    s2+="0";
                }
                else
                {
					b--;
					s1+="1";
					s2+="1";
				}
            }
            s1+="0";
            s2+="1";
            a-=1;
        }
        for(int i=1;i<=b;i++) { s1+="1"; s2+="1"; }
        for(int i=1;i<=a;i++) { s1+="0"; s2+="0"; }
        int num0=0,num1=0;
        for(int i=0;i<s1.length();i++)
        {
            if(s1[i]=='1') num1++;
            else num0++;
        }
        if(num1!=bb || num0!=aa) { cout << "NO" << endl; return 0; }
        cout << "YES" << endl;
        cout << s1 << endl;
        cout << s2 << endl;
    }
}
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46
  • 47
  • 48
  • 49
  • 50
  • 51
  • 52
  • 53
  • 54
  • 55
  • 56
  • 57
  • 58
  • 59
  • 60
  • 61
声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/article/detail/54931
推荐阅读
相关标签
  

闽ICP备14008679号