Codeforces Round #671 (Div. 2) (A~E)

Link~
题面差评,整场都在读题

A

根据奇偶性判断一下即可。

#include<bits/stdc++.h>
#define ll long long
#define N
#define rep(i,a,n) for (int i=a;i<=n;i++)
#define per(i,a,n) for (int i=n;i>=a;i--)
#define inf 0x3f3f3f3f
#define pb push_back
#define mp make_pair
#define lowbit(i) ((i)&(-i))
#define VI vector<int>
using namespace std;
int t,n;
string s;
int main(){
	//freopen(".in","r",stdin);
	//freopen(".out","w",stdout);
 	cin>>t;
 	while(t--){
 		cin>>n;
 		cin>>s;
 		int odd,even;odd = even = -1;
 		if(n&1){
 			rep(i,0,n-1){
 				if((i&1)==0){
 					int v = s[i]-'0';
 					if(v&1) odd = 1;
 					else even = 1;
 				}
 			}
 			if(odd != -1) puts("1");
 			else puts("2");
 		}else{
 			rep(i,0,n-1){
 				if((i&1)==1){
 					int v = s[i]-'0';
 					//cout << "v: " <<v << endl;
 					if(v&1) odd = 1;
 					else even = 1;
 				}
 			}
 			if(even != -1) puts("2");
 			else puts("1");
 		}

 	}
	return 0;
}

B

神必题意,读了快半小时才明白题意。
看着题目给的图的找个规律就行了。

#include<bits/stdc++.h>
#define int long long
#define N 1000015
#define rep(i,a,n) for (int i=a;i<=n;i++)
#define per(i,a,n) for (int i=n;i>=a;i--)
#define inf 0x3f3f3f3f
#define pb push_back
#define mp make_pair
#define lowbit(i) ((i)&(-i))
#define VI vector<int>
using namespace std;
int t,n,x,val[N];
int qpow(int a,int b){
	int res = 1;
	while(b){
		if(b&1) res = res*a;
		a = a*a;
		b>>=1;
	}
	return res;
}
signed main(){
	//freopen(".in","r",stdin);
	//freopen(".out","w",stdout);
 	cin>>t;n = 31;
 	rep(i,1,n) val[i] = val[i-1]*2+qpow(4,i-1);
 	rep(i,1,n) val[i] += val[i-1];//,cout << val[i] << endl;
 	while(t--){
 		cin>>x;
 		int l = 1,r = n,ans = 0;
 		while(l+3 < r){
 			int mid = (l+r)>>1;
 			if(val[mid] <= x) l = mid;
 			else r = mid;
 		}
 		rep(i,l,r){
 			if(val[i] <= x) ans = max(ans,i);
 		}
 		cout << ans << endl;
 	}
	return 0;
}

C

大力分类讨论题,WA了好多发

#include<bits/stdc++.h>
#define int long long
#define N 1005
#define rep(i,a,n) for (int i=a;i<=n;i++)
#define per(i,a,n) for (int i=n;i>=a;i--)
#define inf 0x3f3f3f3f
#define pb push_back
#define mp make_pair
#define lowbit(i) ((i)&(-i))
#define VI vector<int>
using namespace std;
int t,n,a[N];
signed main(){
	//freopen(".in","r",stdin);
	//freopen(".out","w",stdout);
 	cin>>t;
 	while(t--){
 		int ans = inf,cur,ff = 0;
 		cin>>n>>cur;
 		rep(i,1,n) cin>>a[i];
 		int sum = 0;rep(i,1,n) sum += a[i];
 		rep(i,1,n) if(a[i] == cur) ff++;
 		if(n*cur == sum) ans = min(ans,1ll);
 		if(ff == n) ans = min(ans,0ll);
 		if(ff > 1){
 			ans = min(ans,1ll);
 		}else{
 			ans = min(ans,2ll);
 		}
 		int left = n-ff;
 		if(left < n) ans = min(ans,1ll);
 		if(sum%n == 0){
 			if(ff) ans = min(ans,1ll);
 		}
 		cout << ans << endl;
 	}
	return 0;
}

D

贪心构造

#include<bits/stdc++.h>
#define ll long long
#define N 100015
#define rep(i,a,n) for (int i=a;i<=n;i++)
#define per(i,a,n) for (int i=n;i>=a;i--)
#define inf 0x3f3f3f3f
#define pb push_back
#define mp make_pair
#define lowbit(i) ((i)&(-i))
#define VI vector<int>
using namespace std;
int n,a[N],b[N];
int main(){
	//freopen(".in","r",stdin);
	//freopen(".out","w",stdout);
 	cin>>n;
 	rep(i,1,n) cin>>a[i];
 	sort(a+1,a+n+1);int l = 1,r = n/2+1;
 	rep(i,1,n){
 		if(i&1) b[i] = a[r++];
 		else b[i] = a[l++];
 	}
 	int cnt = 0;
 	rep(i,2,n-1){
 		if(b[i] < b[i-1]&&b[i] < b[i+1]) cnt++;
 	}
 	cout << cnt << endl;
 	rep(i,1,n) cout << b[i] << ' ';
	return 0;
}

E

特判\(n = p*q\)的情况,其中\(p,q\)是质数,答案为\(1\),直接输出即可。
否则答案为零,在这里插入图片描述

这样围成一个圈就行了。

垃圾场,让人挺不爽的,因为奇怪的原因被区分,可能是手速和英语不太行。

posted @ 2020-11-17 22:29  趁着胆子小  阅读(165)  评论(0编辑  收藏  举报
//explotion effect (unabled)