Codeforces Round #664 题解(A ~ C)

1395A - Boboniu Likes to Color Balls

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

#include<bits/stdc++.h>
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

假设fij=i+Sx2modn+1j+Sy2mod(m+1)
将i从1迭代到n:如果i为奇数,则打印fi1fi2fim
否则打印fimfim1fi1

#include <bits/stdc++.h>
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。因此,对于所有i1inci|A=A
由于aibi<29,我们可以枚举从0291的所有整数,并检查每个i是否存在jaibj|A=A。 最少的就是答案。
时间复杂度为O29n2

#include<bits/stdc++.h>
#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<<i))?ans^=(1<<i):0;
	printf("%d",ans);
	return 0;
}
posted @   RioTian  阅读(280)  评论(1编辑  收藏  举报
编辑推荐:
· 探究高空视频全景AR技术的实现原理
· 理解Rust引用及其生命周期标识(上)
· 浏览器原生「磁吸」效果!Anchor Positioning 锚点定位神器解析
· 没有源码,如何修改代码逻辑?
· 一个奇形怪状的面试题:Bean中的CHM要不要加volatile?
阅读排行:
· 分享4款.NET开源、免费、实用的商城系统
· Obsidian + DeepSeek:免费 AI 助力你的知识管理,让你的笔记飞起来!
· MongoDB 8.0这个新功能碉堡了,比商业数据库还牛
· 白话解读 Dapr 1.15:你的「微服务管家」又秀新绝活了
· 全程不用写代码,我用AI程序员写了一个飞机大战
点击右上角即可分享
微信分享提示

📖目录