1395A - Boboniu Likes to Color Balls

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

  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. typedef long long ll;
  4. ll r, g, b, w;
  5. int main() {
  6. //freopen("in.txt", "r", stdin);
  7. ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
  8. int t; cin >> t; while (t--) {
  9. cin >> r >> g >> b >> w;
  10. ll c = r + g + b + w;
  11. int cnt = (r & 1) + (g & 1) + (b & 1);
  12. if (cnt == 0 || cnt == 3)cout << "Yes" << endl;
  13. else if(c & 1){
  14. if (cnt == 2 && r && g && b)w += 3, cnt = 1;
  15. if (cnt == 2) cout << "No\n";
  16. else if (w & 1) cout << "No\n";
  17. else cout << "Yes" << endl;
  18. } else cout << "No" << endl;
  19. }
  20. }

1395B - Boboniu Plays Chess

假设Codeforces Round #664 题解(A ~ C) - 图1%EF%BC%89#card=math&code=f%EF%BC%88i%EF%BC%8Cj%EF%BC%89%20%3D%EF%BC%88%EF%BC%88i%20%2B%20Sx-2%EF%BC%89modn%20%2B%201%EF%BC%8C%20%EF%BC%88j%20%2B%20Sy-2%EF%BC%89mod%20%28m%20%2B%201%29%EF%BC%89)。
将i从1迭代到n:如果i为奇数,则打印Codeforces Round #664 题解(A ~ C) - 图2
否则打印Codeforces Round #664 题解(A ~ C) - 图3

  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. const int maxn = 100;
  4. int n, m, a, b;
  5. bool row[maxn + 3], vis[maxn + 3][maxn + 3];
  6. int main() {
  7. scanf("%d %d %d %d", &n, &m, &a, &b);
  8. for (int i = 1; i <= n; i++) {
  9. if (i > 1) for (int j = 1; j <= n; j++) if (!row[j]) { a = j; break; }
  10. row[a] = true;
  11. printf("%d %d\n", a, b);
  12. vis[a][b] = true;
  13. for (int j = 1; j < m; j++) {
  14. for (int k = 1; k <= m; k++) if (!vis[a][k]) { b = k; break; }
  15. printf("%d %d\n", a, b);
  16. vis[a][b] = true;
  17. }
  18. }
  19. return 0;
  20. }

1395C - Boboniu and Bit Operations

假设答案为A。因此,对于所有Codeforces Round #664 题解(A ~ C) - 图4
由于Codeforces Round #664 题解(A ~ C) - 图5,我们可以枚举从Codeforces Round #664 题解(A ~ C) - 图6的所有整数,并检查每个i是否存在Codeforces Round #664 题解(A ~ C) - 图7。 最少的就是答案。
时间复杂度为Codeforces Round #664 题解(A ~ C) - 图8

  1. #include<bits/stdc++.h>
  2. #define ci const int&
  3. using namespace std;
  4. int n,m,p[210],d[210],ans;
  5. bool Check(ci x){
  6. for(int i=1;i<=n;++i){
  7. for(int j=1;j<=m;++j)if(((p[i]&d[j])|x)==x)goto Next;
  8. return 0;
  9. Next:;
  10. }
  11. return 1;
  12. }
  13. int main(){
  14. scanf("%d%d",&n,&m);
  15. for(int i=1;i<=n;++i)scanf("%d",&p[i]);
  16. for(int i=1;i<=m;++i)scanf("%d",&d[i]);
  17. ans=(1<<9)-1;
  18. for(int i=8;i>=0;--i)Check(ans^(1<<i))?ans^=(1<<i):0;
  19. printf("%d",ans);
  20. return 0;
  21. }