首页 > 其他 > 详细

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

时间:2014-09-14 12:38:57      阅读:142      评论:0      收藏:0      [点我收藏+]

题目链接: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处于被动状态,也就是必败点。

     

bubuko.com,布布扣
 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

 

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

原文:http://www.cnblogs.com/windysai/p/3970824.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!