zoukankan      html  css  js  c++  java
  • HDU 4994 博弈。

    F - 6
    Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u

    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




    思路: 博弈, 先找必胜状态或必败状态, 判断控制权在谁手里,他就必胜, 判断控制权在谁手里就判断第一个非1的数钱有几个1 如果是偶数个控制权就在第一个手里。


    代码:

    #include<stdio.h>
    #include<string.h>
    
    #define N 110000
    int main(void)
    {
    int t, i, j, n, f, ok;
    int a[N];
    scanf("%d", &t);
    
    while(t--)
    {
    f = 0;
    ok = 1;
    
    scanf("%d", &n);
    
    for(i = 0; i < n; i++)
    scanf("%d", &a[i]);
    
    for(i = 0; i < n; i++)
    {
    if(a[i] > 1)
    {
    ok = 0;//判断是否全是1.
    break;
    }
    
    else
    f++;//判断第一个不是1的位置。
    }
    
    if(ok==0)//如果有非1的存在,就判断控制权再谁手里, 如果在第一非1的数前有偶数个1控制权在第一个人手里。
    {
    if(f%2)
    printf("No
    ");
    else
    printf("Yes
    ");
    }
    else//如果全是1的话,如果有奇数堆第一个人必胜。
    {
    if(f%2)
    printf("Yes
    ");
    else
    printf("No
    ");
    }
    
    }
    return 0;
    
    }
  • 相关阅读:
    Appium Desktop使用
    mumu模拟器使用
    adb
    测试准出
    缺陷管理
    测试准入检查
    测试工作流程
    需求测试分析
    异常字符测试
    今日总结
  • 原文地址:https://www.cnblogs.com/dll6/p/5782820.html
Copyright © 2011-2022 走看看