UVA 11892 - ENimEN (简单博弈)

题目地址: http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&category=478&problem=2992&mosmsg=Submission+received+with+ID+12239557


题意:有n堆石子,每堆的个数为ai,每次可以取一堆中任意非0个数石子,取到最后石子为胜。 
新增条件是:每个人只能在对手最后取过的堆里取,除非对手把堆取完 

题解:
简单的推理,先考虑1~n堆,每堆都是1 
1 先,1 1后,1 1 1先,1 1 1 1后,。。。如此交替 
再推倒出现非1的情况,非1数设为x 
x先, 
1 x->1 1先,x x->1 x->x先 
1 1 x->1 1先,1 x x->1 x 1->1 x先,x x x->x x 1->x x先 
。。。 
可发现除了全是1的情况,其他都能根据已知条件推出先手必胜 


AC代码:

 

#include <iostream>

#include <cstdio>

#include <cstring>

#include <string>

#include <cstdlib>

#include <cmath>

#include <vector>

#include <list>

#include <deque>

#include <queue>

#include <iterator>

#include <stack>

#include <map>

#include <set>

#include <algorithm>

#include <cctype>

#include <ctime>

using namespace std;



typedef long long LL;

const int N=100005;

const int INF=0x3f3f3f3f;

const double PI=acos(-1.0);



int main()

{

    int i,T;

    cin>>T;

    while(T--)

    {

        int a,n,f=0;

        scanf("%d",&n);

        for(i=0;i<n;i++)

        {

            scanf("%d",&a);

            if(a!=1)

                f=1;

        }

        if(f==0&&n%2==0)

            puts("piloop");

        else

            puts("poopi");

    }

    return 0;

}


 

 

你可能感兴趣的:(uva)