Codeforces Round #664 题解(A ~ C)

1395A - Boboniu Likes to Color Balls

如果在r,b,g,w中小于或等于一个奇数,则可以将其定为回文。
否则,请进行一次操作(如果可以),然后检查上述情况。
进行多次操作是没有意义的,因为我们只关心r,b,g,w的奇偶性

#include
using namespace std;
typedef long long ll;
ll r, g, b, w;
int main() {
	//freopen("in.txt", "r", stdin);
	ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
	int t; cin >> t; while (t--) {
		cin >> r >> g >> b >> w;
		ll c = r + g + b + w;
		int cnt = (r & 1) + (g & 1) + (b & 1);
		if (cnt == 0 || cnt == 3)cout << "Yes" << endl;
		else if(c & 1){
			if (cnt == 2 && r && g && b)w += 3, cnt = 1;
			
			if (cnt == 2) cout << "No\n";
			else if (w & 1) cout << "No\n";
			else cout << "Yes" << endl;
		} else cout << "No" << endl;
	}
}

1395B - Boboniu Plays Chess

假设\(f(i,j) =((i + Sx-2)modn + 1, (j + Sy-2)mod (m + 1))\)
将i从1迭代到n:如果i为奇数,则打印\(f(i,1),f(i,2),…,f(i,m)\)
否则打印\(f(i,m),f(i,m-1),…,f(i,1)\)

#include 
using namespace std;

const int maxn = 100;
int n, m, a, b;
bool row[maxn + 3], vis[maxn + 3][maxn + 3];

int main() {
	scanf("%d %d %d %d", &n, &m, &a, &b);
	for (int i = 1; i <= n; i++) {
		if (i > 1) for (int j = 1; j <= n; j++) if (!row[j]) { a = j; break; }
		row[a] = true;
		printf("%d %d\n", a, b);
		vis[a][b] = true;
		for (int j = 1; j < m; j++) {
			for (int k = 1; k <= m; k++) if (!vis[a][k]) { b = k; break; }
			printf("%d %d\n", a, b);
			vis[a][b] = true;
		}
	}
	return 0;
}	

1395C - Boboniu and Bit Operations

假设答案为A。因此,对于所有\(i(1≤i≤n),c_i | A = A\)
由于\(a_i,b_i <2^9\),我们可以枚举从\(0到2^9-1\)的所有整数,并检查每个i是否存在\(j(ai&bj)| A = A\)。 最少的就是答案。
时间复杂度为\(O(2^9⋅n^2\)

#include
#define ci const int&
using namespace std;
int n,m,p[210],d[210],ans;
bool Check(ci x){
	for(int i=1;i<=n;++i){
		for(int j=1;j<=m;++j)if(((p[i]&d[j])|x)==x)goto Next;
		return 0;
		Next:;
	}
	return 1;
}
int main(){
	scanf("%d%d",&n,&m);
	for(int i=1;i<=n;++i)scanf("%d",&p[i]);
	for(int i=1;i<=m;++i)scanf("%d",&d[i]);
	ans=(1<<9)-1;
	for(int i=8;i>=0;--i)Check(ans^(1<

你可能感兴趣的:(Codeforces Round #664 题解(A ~ C))