zoukankan      html  css  js  c++  java
  • UVA

    题意:有n堆石子,两个人拿,拿走最后的石子的人赢,poopi先拿,条件是,每个人必须从另外一个人最后拿过的石子堆中取石子,若那堆石子被拿没了,才可以自由地拿其他堆。要求每次拿的石子数不能为0。问谁赢。

    分析:

    1、若每堆石子个数都为1,很显然谁赢只取决于n。
    2、
    (1)若石子堆中有奇数堆石子个数为1,如
    5 2 1 3 1 9 6 1
    则先手poopi只需要每次先从个数不为1的石子堆中拿,并且一下拿走(该石子堆个数-1)个,另一个人只能拿走该石子堆剩下的最后一个石子。
    如此反复,拿完所有个数不为1的石子堆后,就回到了(1),显然剩下奇数堆,先手赢。
    (2)若石子堆中有偶数堆石子个数为1,如
    5 2 1 3 1 9 1 6 1
    则先手只需要先按照2.1的思路一直拿到还剩下一堆不为1的石子堆,此时,轮到先手,先手将这堆不为1的石子堆全部拿走,
    则还剩偶数堆个数为1的石子堆,先手赢。
    综上所述,先手赢。

    #include<cstdio>
    #include<cstring>
    #include<cstdlib>
    #include<cctype>
    #include<cmath>
    #include<iostream>
    #include<sstream>
    #include<iterator>
    #include<algorithm>
    #include<string>
    #include<vector>
    #include<set>
    #include<map>
    #include<stack>
    #include<deque>
    #include<queue>
    #include<list>
    #define lowbit(x) (x & (-x))
    const double eps = 1e-8;
    inline int dcmp(double a, double b){
        if(fabs(a - b) < eps) return 0;
        return a > b ? 1 : -1;
    }
    typedef long long LL;
    typedef unsigned long long ULL;
    const int INT_INF = 0x3f3f3f3f;
    const int INT_M_INF = 0x7f7f7f7f;
    const LL LL_INF = 0x3f3f3f3f3f3f3f3f;
    const LL LL_M_INF = 0x7f7f7f7f7f7f7f7f;
    const int dr[] = {0, 0, -1, 1, -1, -1, 1, 1};
    const int dc[] = {-1, 1, 0, 0, -1, 1, -1, 1};
    const int MOD = 1e9 + 7;
    const double pi = acos(-1.0);
    const int MAXN = 20000 + 10;
    const int MAXT = 10000 + 10;
    using namespace std;
    int a[MAXN];
    int main(){
        int T;
        scanf("%d", &T);
        while(T--){
            int N;
            scanf("%d", &N);
            int cnt = 0;
            for(int i = 0; i < N; ++i){
                scanf("%d", &a[i]);
                if(a[i] == 1) ++cnt;
            }
            if(cnt == N){
                if(cnt & 1){
                    printf("poopi
    ");
                }
                else{
                    printf("piloop
    ");
                }
                continue;
            }
            printf("poopi
    ");
        }
        return 0;
    }
    

      

  • 相关阅读:
    Kotlin基本语法笔记3之定义类、继承及创建实例
    Kotlin基本语法笔记2之类型检测及自动类型转换、循环
    Kotlin基本语法笔记之函数、变量的定义及null检测
    C++笔记之外部类访问内部类的私有成员
    正则表达式之不区分大小写的匹配
    springMVC之helloworld
    数组学习
    反射reflect
    JSP学习
    自己做的菜
  • 原文地址:https://www.cnblogs.com/tyty-Somnuspoppy/p/7241952.html
Copyright © 2011-2022 走看看