题目:http://codeforces.com/contest/862/problem/C
题意:构造n个数字 使这些数字异或值为m
题解:从0开始,每连续4个数字数字xor值为0 则可以减少为4种情况。因为不同的两个数字异或不可能为0,所以m为0单独讨论。(忽略代码的丑陋)
1 #define _CRT_SECURE_NO_DEPRECATE 2 #pragma comment(linker, "/STACK:102400000,102400000") 3 #include<iostream> 4 #include<cstdio> 5 #include<fstream> 6 #include<iomanip> 7 #include<algorithm> 8 #include<cmath> 9 #include<deque> 10 #include<vector> 11 #include<bitset> 12 #include<queue> 13 #include<string> 14 #include<cstring> 15 #include<map> 16 #include<stack> 17 #include<set> 18 #include<functional> 19 #define pii pair<int, int> 20 #define mod 1000000007 21 #define mp make_pair 22 #define pi acos(-1) 23 #define eps 0.00000001 24 #define mst(a,i) memset(a,i,sizeof(a)) 25 #define all(n) n.begin(),n.end() 26 #define lson(x) ((x<<1)) 27 #define rson(x) ((x<<1)|1) 28 #define inf 0x3f3f3f3f 29 typedef long long ll; 30 typedef unsigned long long ull; 31 using namespace std; 32 33 34 int main() 35 { 36 ios::sync_with_stdio(false); 37 cin.tie(0); cout.tie(0); 38 int i, j, k, m, n; 39 cin >> n >> m; 40 if (n == 2 && m == 0) { cout << "NO" << endl; return 0; } 41 cout << "YES" << endl; 42 if (m != 0) 43 { 44 int temp = (n - 1) / 4; 45 for (int i = 100004; i <= 100004 + temp * 4 - 1; ++i) 46 cout << i << " "; 47 n -= temp * 4; 48 if (n == 1)cout << m << endl; 49 else if (n == 4) 50 { 51 if(m!=2) 52 cout << "2 524290 524288 " << m; 53 else 54 cout << "4 524292 524288 " << m; 55 } 56 else if (n == 2) 57 cout << m + 524288 << " 524288"; 58 else if (n == 3) 59 cout << "0 " << m + 524288 << " 524288"; 60 } 61 else 62 { 63 int temp = max(n / 4 - 1, 0); 64 for (int i = 100004; i <= 100004 + temp * 4 - 1; ++i) 65 cout << i << " "; 66 n -= temp * 4; 67 if (n == 6) 68 { 69 cout << "1 2 3 7 8 15"; n -= 6; 70 } 71 else if (n >= 4) 72 { 73 cout << "500000 500001 500002 500003 "; n -= 4; 74 } 75 if (n == 1) 76 cout << "0" << endl; 77 else if (n == 3) 78 cout << "1 2 3" << endl; 79 } 80 return 0; 81 }