Luogu P2148 [SDOI2009]E&D

题目链接 $$Click$$ $$Here$$

#include<cstdio>
#include<bitset>
#include<iostream>
using namespace std;

const int N = 10;
const int M = N + 1;//随便调大小

int ans[M][M];
bitset <M> s[M];

int mex (bitset <M> b) {
int res = 0;
while (b[res]) ++res;
return res;
}

int main () {
for(int i = 2; i <= N; ++i) {
for (int j = 1, k = i - 1; k; ++j, --k) {
s[i].set (ans[j][k] = mex (s[j] | s[k]));//枚举合并
}
}
for (int i = 0; i < N; ++i) printf ("%3d", i); printf ("\n");
for (int i = 1; i < N; ++i){//输出矩阵
printf ("%2d:", i);
for (int j = 1; i + j <= N; ++j) {
printf ("%3d", ans[i][j]);
}
printf ("\n");
}
for(int i = 1; i <= N; ++i) {//输出对于每一个a，所有c+d=a的(c,d)的SG值集合
printf ("%2d:SG%d ", i, mex (s[i]));
cout << s[i] << endl;
}
return 0;
}



$$STD:$$

#include <bits/stdc++.h>
using namespace std;

int T, n, x, y, z, cnt, ans;

int main () {
cin >> T;
while (T--) {
ans = 0;
cin >> n; n >>= 1;
while (n--) {
cnt = 0;
cin >> y >> z;
x = (y - 1) | (z - 1);
while (x & 1) {
++cnt;
x >>= 1;
}
ans ^= cnt;
}
puts (ans ? "YES" : "NO");
}
return 0;
}



posted @ 2019-03-11 08:27  maomao9173  阅读(97)  评论(0编辑  收藏  举报