alwaysBeAStarter

博客园 首页 新随笔 联系 订阅 管理

 题目链接:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=1507

MisereNim博弈。代码如下:

 1 //============================================================================
 2 // Name        : test.cpp
 3 // Author      : 
 4 // Version     :
 5 // Copyright   : Your copyright notice
 6 // Description : Hello World in C++, Ansi-style
 7 //============================================================================
 8 
 9 #include <iostream>
10 #include <math.h>
11 #include <stdio.h>
12 #include <cstdio>
13 #include <algorithm>
14 #include <string.h>
15 #include <string>
16 #include <sstream>
17 #include <cstring>
18 #include <queue>
19 #include <vector>
20 #include <functional>
21 #include <cmath>
22 #include <set>
23 #define SCF(a) scanf("%d", &a)
24 #define IN(a) cin>>a
25 #define FOR(i, a, b) for(int i=a;i<b;i++)
26 #define Infinity 999999999
27 #define NInfinity -999999999
28 #define PI 3.14159265358979323846
29 #define MAXN 1000000005
30 #define RATIO (sqrt(5.0)+1.0)/2.0
31 typedef long long Int;
32 using namespace std;
33 
34 int main()
35 {
36     int t;
37     int n;
38     SCF(t);
39     while (t--)
40     {
41         SCF(n);
42         int ans = 0;
43         int num;
44         bool flag = false;
45         FOR(i, 0, n)
46         {
47             SCF(num);
48             if (num > 1)
49                 flag = true;
50             ans = ans^num;
51         }
52         if (flag)
53         {
54             if (ans == 0)
55                 printf("2\n");
56             else
57                 printf("1\n");
58         }
59         else
60         {
61             if (ans == 0)
62                 printf("1\n");
63             else
64                 printf("2\n");
65         }
66     }
67     return 0;
68 }

 

posted on 2017-06-29 17:54  alwaysBeAStarter  阅读(96)  评论(0编辑  收藏  举报