24.台阶-Nim游戏 博弈论

 

 如果奇数级台阶上的石子数异或和不等于0,先手必胜

如果奇数级台阶上的石子数异或和等于0,先手必败

 1 #include <bits/stdc++.h>
 2 using namespace std;
 3 int main() {
 4     int n;
 5     cin >> n;
 6     int res = 0;
 7     for (int i = 1; i <= n; i++) {
 8         int x;
 9         cin >> x;
10         if (i & 1) {
11             res ^= x;
12         }
13     }
14     if (res) {
15         cout << "Yes" << endl;
16     } else {
17         cout << "No" << endl;
18     }
19     return 0;
20 }

 

posted @ 2020-08-21 11:23  kyk333  阅读(113)  评论(0)    收藏  举报