标签:style http color io os ar for sp 代码
题意:取石子游戏,两个人轮流取石子,取石子有规则,要么那掉这堆石子,要么将这堆石子分成两堆,在加入原来的石堆当中,先手取完算胜利,否则失败。
思路:简单的Nim游戏,所有值异或为0时,先手失败。
代码:
#include <iostream> #include <cstdio> #include <cstring> #include <cmath> #include <algorithm> using namespace std; const int MAXN = 100005; int arr[MAXN]; int main() { int n; while (scanf("%d", &n) != EOF) { for (int i = 0; i < n; i++) scanf("%d", &arr[i]); int sum = 0; for (int i = 0; i < n; i++) sum ^= arr[i]; if (sum == 0) printf("Lose\n"); else printf("Win\n"); } return 0; }
标签:style http color io os ar for sp 代码
原文地址:http://blog.csdn.net/u011345461/article/details/39277509