zoukankan      html  css  js  c++  java
  • hdu 4994(博弈)

    Revenge of Nim

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


    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
     
    题意:按照顺序取完n堆石子,每次取一个或者一堆。
    关键点:看出取到第一个>1的石子堆的人是必胜态。
    /**
    对于某个人来说,只要他能够取到第一个>1的堆,那么他就可以决定后面的人的状态了,所以第一个取到>1的堆的人
    是赢家。所以我们只要讨论前面有多少==1的堆就行了。
    2.如果里面存在>1的堆,那么在第一个>1的堆前面有偶数个=1的堆先手才会赢
    1.如果没有>1的堆,那么奇数个=1的堆先手就会赢。
    */
    #include <iostream>
    #include <stdio.h>
    #include <string.h>
    #include <algorithm>
    using namespace std;
    typedef long long LL;
    
    int main()
    {
        int tcase;
        scanf("%d",&tcase);
        while(tcase--)
        {
            int n,cnt=0,v;
            bool flag = false;
            scanf("%d",&n);
            for(int i=1; i<=n; i++)
            {
                scanf("%d",&v);
                if(v>1&&!flag)
                {
                    flag = true;
                    cnt = i-1;
                }
            }
            if(!flag) cnt = n;
            if(flag){
                if(cnt%2==1) printf("No
    ");
                else printf("Yes
    ");
            }else{
                if(cnt%2==0) printf("No
    ");
                else printf("Yes
    ");
            }
        }
        return 0;
    }
  • 相关阅读:
    BZOJ 2440: [中山市选2011]完全平方数 [容斥原理 莫比乌斯函数]
    [莫比乌斯反演]【学习笔记】[旧]
    BZOJ 3289: Mato的文件管理[莫队算法 树状数组]
    BZOJ 2705: [SDOI2012]Longge的问题 [欧拉函数]
    Waiting for possible shutdown message on port 4445
    linux对文件赋权限的命令chmod的详细说明
    查看防火墙状态
    Jmeter分布式测试的各种坑之jmeter-server修改ip
    linux服务器查看公网IP信息的方法
    jmeter-server中启动后端口总是不断在变化
  • 原文地址:https://www.cnblogs.com/liyinggang/p/5642593.html
Copyright © 2011-2022 走看看