zoukankan      html  css  js  c++  java
  • Stone Game II(思维博弈)

    Stone Game II comes. It needs two players to play this game. There are some piles of stones on the desk at the beginning. Two players move the stones in turn. At each step of the game the player should do the following operations.
      First, choose a pile of stones. (We assume that the number of stones in this pile is n)
      Second, take some stones from this pile. Assume the number of stones left in this pile is k. The player must ensure that 0 < k < n and (k XOR n) < n, otherwise he loses.
      At last, add a new pile of size (k XOR n). Now the player can add a pile of size ((2*k) XOR n) instead of (k XOR n) (However, there is only one opportunity for each player in each game).
    The first player who can't do these operations loses. Suppose two players will do their best in the game, you are asked to write a program to determine who will win the game.


    Input  The first line contains the number T of test cases (T<=150). The first line of each test cases contains an integer number n (n<=50), denoting the number of piles. The following n integers describe the number of stones in each pile at the beginning of the game.
    You can assume that all the number of stones in each pile will not exceed 100,000.
    Output  For each test case, print the case number and the answer. if the first player will win the game print "Yes"(quotes for clarity) in a single line, otherwise print "No"(quotes for clarity).
    Sample Input
    3
    2
    1 2
    3
    1 2 3
    4
    1 2 3 3
    Sample Output
    Case 1: No
    Case 2: Yes
    Case 3: No


        Stone Game II comes. It needs two players to play this game. There are some piles of stones on the desk at the beginning. Two players move the stones in turn. At each step of the game the player should do the following operations.
          First, choose a pile of stones. (We assume that the number of stones in this pile is n)
          Second, take some stones from this pile. Assume the number of stones left in this pile is k. The player must ensure that 0 < k < n and (k XOR n) < n, otherwise he loses.
          At last, add a new pile of size (k XOR n). Now the player can add a pile of size ((2*k) XOR n) instead of (k XOR n) (However, there is only one opportunity for each player in each game).
        The first player who can't do these operations loses. Suppose two players will do their best in the game, you are asked to write a program to determine who will win the game.
    Input
          The first line contains the number T of test cases (T<=150). The first line of each test cases contains an integer number n (n<=50), denoting the number of piles. The following n integers describe the number of stones in each pile at the beginning of the game.
        You can assume that all the number of stones in each pile will not exceed 100,000.
    Output
          For each test case, print the case number and the answer. if the first player will win the game print "Yes"(quotes for clarity) in a single line, otherwise print "No"(quotes for clarity).
    Sample Input
    
        3
        2
        1 2
        3
        1 2 3
        4
        1 2 3 3
    
    Sample Output
    
        Case 1: No
        Case 2: Yes
        Case 3: No
  • 相关阅读:
    计算机网络
    一行代码实现字符串逆序输出
    移动前端开发初涉篇【2014/03/25】
    小识闭包【2013/07/18】
    [转载]IE6Bug之躲猫猫【2013/10/29】
    关于maven仓库镜像
    关于spring resttemplate超时设置
    关于springboot访问多个mysql库
    关于Java基础类型自动装箱(autoboxing)
    关于Java(JDBC连接数据库)
  • 原文地址:https://www.cnblogs.com/ellery/p/11716555.html
Copyright © 2011-2022 走看看