• HDU 4994 拿石子


    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
    题意:给n个堆,每个堆有a[i]个石子,每次必须拿一个石子,第一个人先拿然后第二个人拿,最后一个石子如果是第一个人拿的话输出No,否则输出Yes。

    思路:在最初的一个不是1的堆的时候,保证A先拿,
    则前n-1个数(都是1的时候)的和保证是偶数,则A可以胜利。

    #include <cstring>
    #include <cstdio>
    #include <iostream>
    #include <algorithm>
    #include <cmath>
    #include <stack>
    #include <vector>
    #include <queue>
    #include <cmath>
    using namespace std;
    #define N 10500
    int main()
    {
        int n,t;
        int sum;
        int a[N];
        scanf("%d", &t);
        while(t--)
        {
            memset(a,0,sizeof(a));
            sum = 0;
            scanf("%d",&n);
            for(int i=0; i<n; i++)
                scanf("%d",&a[i]);
    
            for(int i=0; i<n-1; i++)
            {
                if(a[i]==1)
                    sum ++;
                else
                    break;
            }
            if(sum % 2 != 0)
                printf("No
    ");
            else
                printf("Yes
    ");
        }
    
        return 0;
    }
  • 相关阅读:
    PHP xml_get_current_column_number() 函数
    PHP xml_get_current_byte_index() 函数
    PHP xml_error_string() 函数
    PHP utf8_encode() 函数
    PHP utf8_decode() 函数
    MySQL 资料库概论与MySQL 安装
    SEO之网站关键词的优化 :首页,内页关键字,长尾关键字
    前端开发chrome console的使用 :评估表达式 – Break易站
    chrome console的使用 : 异常和错误的处理 – Break易站
    SEO的基本概念 和 提交SITEMAP到搜索引擎
  • 原文地址:https://www.cnblogs.com/biu-biu-biu-/p/5779019.html
Copyright © 2020-2023  润新知