Codeforces Round #629 (Div. 3)

0、前序

本蒟蒻最近CF接连滚粗,于是难得有Div.3,就准备过来打打继续滚粗

1、A Divisibility Problem

题意:

(t)个询问,每次两个数(a)(b),每次操作可以把(a+1),求多少次操作后使得(a)(b)整除。

思路:

真·签到题。
因为只有加,所以我们将(a)加至大于(a)且能被(b)整除的数,输出即可。

code:

#include <iostream>
#include <cstdlib>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <cstring>
#include <queue>
using namespace std;
int T;
int a,b;
int main()
{
	cin>>T;
	while(T--)
	{
		cin>>a>>b;
		if(a%b!=0)
		{
			int temp=(a+b)%b;
			cout<<b-temp<<endl;
		}
		else
		cout<<0<<endl;
	}
    return 0;
}

2、B.K-th Beautiful String

题意:

有一个长度为(n)的字符串,里面有(n-2)个'(a)'和(2)个'(b)'。
求将这些数排列形成的(frac{n(n-1)}{2})个字符串中,字典序的第(k)个字符串是什么。
(T)个询问。

思路:

话说这题卡ULL真的强...
十分钟推出了规律,七十分钟调ULL
找规律不难看出,将(aaaa.....ab₁b₂)转化成(aaa....b₁b₂a)需要(frac{(n-b₁)(n-b₁-1)}{2})步,而那个(b₂)的位置就是将(b₁)处理完后n-剩下的数。

code:

#include <iostream>
#include <cstdlib>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <cstring>
#include <queue>
using namespace std;
unsigned long long T,n,k; //不开ull见祖宗
int main()
{
	cin>>T;
	while(T--)
	{
		cin>>n>>k;
		unsigned long long temp=0,temp2=0;
		for(unsigned long long i=n;i>=1;i--)
		{
			if(k<=i*(i-1)/2)
			{
				temp=i;
				temp2=k-((i-1)*(i-2)/2);
			}
		}
		for(unsigned long long i=1;i<=n;i++)
		{
			if(i==n-temp+1||i==n-temp2+1)
			cout<<'b';
			else
			cout<<'a';
		}
		cout<<endl;
	}
    return 0;
}

3、C.Ternary XOR

题意:

(T)个询问,每次询问给定字符串(s),要求出字符串(a)(b),使得((a[i]+b[i])%3=s[i]),注意要使得(a)(b)中的最大值最小。首位不可为0。

思路:

反正就三种:(s[i])(0)(1)(2)中的一个,分类讨论。

举个栗子:(s[i])(1)

如果(i)(1),那么一定为(2+2)%3=1
否则,假定我们最后将(a)字符串设为偏大的。
如果(f=1),表示(a)字符串已经比(b)大了,高位大>低位大,(1+0<2+2),所以把(0)扔给(a)(1)扔给(b)
否则,将(1)(a)(0)(b)(f=1),表示(a)(b)开始大了。

下面对s[i]为2或3时,也这样分类讨论。注意前导0的问题

code:

#include <iostream>
#include <cstdlib>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <cstring>
#include <queue>
using namespace std;
int T,len;
string s;
int main()
{
	cin>>T;
	while(T--)
	{
		cin>>len;
		cin>>s;
		string a="0",b="0";
		int f=0;
		for(int i=0;i<len;i++)
		{
			if(s[i]=='0'&&i==0)
			{
				a+="2";
				b+="1";
				f=1;
			}
			else if(s[i]=='0')
			{
				a+="0";
				b+="0";
			}
			else if(s[i]=='1'&&i!=0)
			{
				if(f==1)
				{
					a+="0";
					b+="1";
				}
				else
				{
					a+="1";
					b+="0";
					f=1; 
				}
			} 
			else if(s[i]=='1'&&i==0)
			{
				a+="2";
				b+="2";
			}
			else if(s[i]=='2'&&i==0)
			{
				a+="1";
				b+="1";
			}
			else if(s[i]=='2'&&i!=0)
			{
				if(f==1)
				{
					a+="0";
					b+="2";
				}
				else
				{
					a+="1";
					b+="1";
				}
			}
		}
		for(int i=1;i<=len;i++)
		{
			cout<<a[i];
		}
		cout<<endl;
		for(int i=1;i<=len;i++)
		{
			cout<<b[i];
		}
		cout<<endl;
	}
    return 0;
}

4、总结

我这只蒟蒻好菜啊,就把签到的3题全过掉了,后面3题难的一题没过掉...
而且B题还脑抽地交了4遍才过,真是不开ULL见祖宗
最后(rank7000+),好菜啊...
不过因为以前更菜,rat都不到1300了,出 乎 意 料 地+24rat....
mengbier

下次加油吧!争取上1300

by pjx

原文地址:https://www.cnblogs.com/pjxpjx/p/12578755.html