BestCoder8 1002 Revenge of Nim(hdu 4994) 解题报告

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4994

题目意思:有 n 个 heap(假设从左至右编号为1~n),每个 heap 上有一些 objects。有两个player,轮流从左至右的 heap 上取走 object(1 <= 取走数 <= 当前heap上的最多objects数),规定当前的 heapi 如果还有object,那么不能取走heapi+1的object,直到把 heapi 的 object 全部取光。

    题解在这里

    http://bestcoder.hdu.edu.cn/

    其实好容易理解,如果 heap 上的object数一直为1,那么轮到的player1(or player2)只能不得不取走,直到遇到不为1的 heapx,那么此时轮到的player就取得主动权,取走 heapx(假设objects 数为 sum) 中sum-1的数,最后另一个player处于被动状态,也就是必败点。

     

 1 #include <iostream>
 2 #include <cstdio>
 3 #include <cstdlib>
 4 #include <cstring>
 5 using namespace std;
 6 
 7 const int maxn = 1000 + 10;
 8 int a[maxn];
 9 
10 int main()
11 {
12     int T, n, m;
13     while (scanf("%d", &T) != EOF)
14     {
15         while (T--)
16         {
17             scanf("%d", &n);
18             for (int i = 1; i <= n; i++)
19                 scanf("%d", &a[i]);
20             int i = 1;
21             int ok = 1;
22             while (a[i] == 1 && i+1 <= n)
23             {
24                 ok ^= 1;
25                 i++;
26             }
27             printf("%s\n", ok ? "Yes" : "No");
28         }
29     }
30     return 0;
31 }
View Code

 

posted @ 2014-09-14 11:32  windysai  阅读(202)  评论(0编辑  收藏  举报