1. 程式人生 > 其它 >Codeforces Round #698 (Div. 2) 題解

Codeforces Round #698 (Div. 2) 題解

技術標籤:cf

Codeforces Round #698 (Div. 2)

A. Nezzar and Colorful Balls

找數字出現次數最多的個數

map<int,int> book;
int a[maxn];
int main()
{
	int t;
	cin >> t;
	while (t--) {
		book.clear();
		int n;
		cin >> n;
		for(int i=1;i<=n;i++)
		{
			cin >> a[i];
			book[a[i]]++;
		}
		int maxx=
-1; for(int i=1;i<=n;i++) { maxx=max(maxx,book[a[i]]); } cout << maxx << endl; } }

B. Nezzar and Lucky Number

構造,分情況討論

  1. a i ≥ 10 ∗ d {a_i≥10*d} ai10d,那麼一定可以構造成(10d+ a i {a_i} ai%d)+kd的形式(k為整數)
  2. a i < 10 ∗ d {a_i<10*d} ai<10d,判斷能否構造為10n+kd的形式(k為正整數且k<10)
#define ios ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
int main() { ios; int t; cin >> t; while (t--) { int q,d; cin >> q >> d; for(int i=1;i<=q;i++) { int num; cin >> num; bool flag=false; if(num>=10*d) { cout<< "YES" << endl; continue;} for(int k=1;k<=9;k++) { if(
num<k*d) break; if((num-k*d)%10==0) flag=true; } if(flag) cout << "YES" << endl; else cout << "NO" << endl; } } }

C. Nezzar and Symmetric Array

ll d[maxn],dd[maxn];
map<ll,int> book;
int main()
{
	int t;
	scanf("%d",&t);
	while (t--) {
		book.clear();
		ll n,cnt=0;
		scanf("%lld",&n);
		for(int i=1;i<=2*n;i++)
		{
			scanf("%lld",&d[i]);
			book[d[i]]++;
			if(book[d[i]]==1) dd[++cnt]=d[i];
		}
		sort(dd+1, dd+1+cnt);
		bool flag=true;
		for(int i=1;i<=2*n;i++)
		{
			if(book[d[i]]!=2)
			{
				flag=false;
				break;
			}
		}
		ll a1r=0;
		if(flag)
		{
			for(int i=n;i>=2;i--)
			{
				ll tmp=dd[i]-dd[i-1],tt=2*(i-1);
				if(tmp%tt) { flag=0; break;}
				a1r+=(n-i+1)*tmp/tt;
			}
		}
		if(dd[1]<=2*a1r || (dd[1]-2*a1r)%n || (dd[1]-2*a1r)/n%2) flag=0;
		if(flag) printf("YES\n");
		else printf("NO\n");
	}
}