码迷,mamicode.com
首页 > 其他好文 > 详细

hdu4994Revenge of Nim(博弈)

时间:2014-09-13 12:08:15      阅读:190      评论:0      收藏:0      [点我收藏+]

标签:des   style   blog   http   color   io   os   java   ar   

题目链接:

选我选我
就是有n堆物品,然后只有一堆物品完全选完后,才能选好后面的,看最后谁赢。
思路:
确定第一个不为1的是轮到谁,如果谁得到了这个优势,那么他就必胜。。因为他可以人为控制后面的顺序了。。

题意:

题目:

Revenge of Nim

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 259    Accepted Submission(s): 119


Problem Description
Nim is a mathematical game of strategy in which two players take turns removing objects from distinct heaps. On each turn, a player must remove at least one object, and may remove any number of objects provided they all come from the same heap.
---Wikipedia

Today, Nim takes revenge on you. The rule of the game has changed a little: the player must remove the objects from the current head(first) heap. Only the current head heap is empty can the player start to remove from the new head heap. As usual, the player who takes the last object wins.
 

Input
The first line contains a single integer T, indicating the number of test cases. 

Each test case begins with an integer N, indicating the number of heaps. Then N integer Ai follows, indicating the number of each heap successively, and the player must take objects in this order, from the first to the last.

[Technical Specification]
1. 1 <= T <= 100
2. 1 <= N <= 1 000
3. 1 <= Ai <= 1 000 000 000
 

Output
For each test case, output “Yes” if the first player can always win, otherwise “No”.
 

Sample Input
2 1 2 2 1 1
 

Sample Output
Yes No
 

Source
 

Recommend
heyang   |   We have carefully selected several similar problems for you:  4996 4995 4992 4991 4990 
 

代码:
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<map>
#include<vector>
#include<cmath>
#include<string>
#include<queue>
#define eps 1e-9
#define ll long long
#define INF 0x3f3f3f3f
using namespace std;

const int maxn=1000+10;

int a[maxn];

int main()
{
    int t,n,cnt,ok;
    scanf("%d",&t);
    while(t--)
    {
        cnt=ok=0;
        scanf("%d",&n);
        for(int i=1;i<=n;i++)
            scanf("%d",&a[i]);
        for(int i=1;i<=n;i++)
        {
            if(a[i]==1)
                cnt++;
            else 
            {
                ok=1;
                break;
            }
        }
        if(ok)
        {
           if(cnt%2)
              puts("No");
           else 
              puts("Yes");
        }
        else 
        {
            if(cnt%2)
              puts("Yes");
            else 
             puts("No"); 
        }
    }
    return 0;
}



hdu4994Revenge of Nim(博弈)

标签:des   style   blog   http   color   io   os   java   ar   

原文地址:http://blog.csdn.net/u014303647/article/details/39250013

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!