UVA - 11892 ENimEN(博弈)

题意:有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\n");
            }
            else{
                printf("piloop\n");
            }
            continue;
        }
        printf("poopi\n");
    }
    return 0;
}

  

转载于:https://www.cnblogs.com/tyty-Somnuspoppy/p/7241952.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值