zoukankan      html  css  js  c++  java
  • HDU 6266(思维+规律)

        题面:

    Problem C. Hakase and Nano

    Hakase and Nano are playing an ancientpebble game (pebble is a kind of rock). There are n packs ofpebbles, and the i-th pack contains ai pebbles. They take turns to pick up pebbles. In each turn, they canchoose a pack arbitrarily and pick up at least one pebble in this pack. Theperson who takes the last pebble wins.

    This time, Hakase cheats. In each turn,she must pick pebbles following the rules twice continuously. Suppose bothplayers play optimally, can you tell whether Hakase will win?

    Input

    The first line contains an integer T (1 ≤ T ≤20) representing the number of test cases.

    For each test case, thefirst line of description contains two integers n(1 ≤ n ≤ 106) and d (d = 1 or d = 2). If d = 1, Hakase takes firstand if d = 2, Nano takes first. n represents thenumber of pebble packs.

    The second line contains n integers, the i-th integer ai (1 ≤ ai≤ 109) represents the number ofpebbles in the i-th pebble pack.

    Output

    For each test case, print “Yes” or “No” in one line.If Hakase can win, print “Yes”, otherwise,print “No”.

    Example

    standard input

     

    standard output

    2

    3 1

    1 1 2

    3 2

    1 1 2

    Yes

    No

     


        题面描述:Nim博弈变形,这次两个人中的一个人必须取两次石头,询问是否必胜。

        题面分析:哎?这是个Nim博弈?那我套个模板改一改就好了吧。
        事实上这题是被隐藏挺深的规律题。如果被Nim博弈限制住思维的话可能就会一直被卡。

        正确的做法其实就是最原始的找规律。我们可以发现,当Hakase先手的时候(即d==1),只有当出先1 1 1或者1 1 1 1 1 1......(即石子的堆数为3的倍数且石子的个数为1),Hakase才必输。在其他的情况下Hakase总有方法避免出现上述情况进而导致必胜。
        相反,若Hakase后手的时候(即d==2),根据第一种情况所分析的,倘若要让Hakase必输,有且仅当Hakase先手的情况下满足情况1的条件。因此,在Nano 先手的时候,唯有能将局面变为石子的堆数为3的倍数且石子的个数为1,Nano才可获得胜利。据此,就不难发现Hakase后手必输的情况有且仅有
        (1)石子的堆数为3的倍数加1且仅有一堆石头的数量不为1
        (2)石子的堆数为3的倍数,且仅有一堆石头的数量不为1

        (3)石子的堆数为3的倍数加1且全部石头的数量都为1
        分析完后,实现就可以通过了。

        

    #include <bits/stdc++.h>
    using namespace std;
    int main()
    {
        int t;
        cin>>t;
        while(t--){
            int n,d;
            cin>>n>>d;
            int cnt=0;
            int tmp;
            if(d==1){
                for(int i=0;i<n;i++){
                    cin>>tmp;
                    if(tmp==1) cnt++;
                }
                if(cnt==n&&n%3==0) puts("No");
                else puts("Yes");
            }
            else{
                for(int i=0;i<n;i++){
                    cin>>tmp;
                    if(tmp==1) cnt++;
                }
                if(cnt==n&&n%3==1||cnt+1==n&&n%3==1||cnt+1==n&&n%3==0){
                    puts("No");
                }
                else puts("Yes");
            }
        }
        return 0;
    }
    

  • 相关阅读:
    链接唤醒IOSApp
    C#抽象属性
    c#结构体与类的区别
    广告学入门
    个性化推荐十大挑战[
    MapReduce 读取和操作HBase中的数据
    mysql sql命令大全
    从B 树、B+ 树、B* 树谈到R 树
    MapReduce操作HBase
    Meanshift,聚类算法
  • 原文地址:https://www.cnblogs.com/Chen-Jr/p/11007302.html
Copyright © 2011-2022 走看看