Untitled

mail@pastecode.io avatar
unknown
plain_text
2 years ago
2.0 kB
2
Indexable
Never
#include <stdio.h>
int pooh_turn(int n);
int piglet_turn(int n);
int A,B,Ma,Mb;
int I1[100005],I2[100005],Pooh[100005],Piglet[100005];
int main()
{
    int T,N;
    char W[8];
    int i,j;
    int ans;
    scanf("%d",&T);

    for(i=0;i<T;i++)
    {
        scanf("%d %d %d %d %d %s",&N,&A,&B,&Ma,&Mb,W);
        for(j=0;j<=N;j++)
        {
            Pooh[j]=2;
            Piglet[j]=2;
        }
        for(j=0;j<Ma;j++)
        {
            scanf("%d",&I1[i]);
        }
        for(j=0;j<Mb;j++)
        {
            scanf("%d",&I2[i]);
        }
        if(W[1]=='o')
        {
            ans=pooh_turn(N);
            if(ans)printf("Pooh\n");
            else{printf("Piglet\n");}
        }
        else
        {
            ans=piglet_turn(N);
            if(ans)printf("Piglet\n");
            else{printf("Pooh\n");}
        }
    }
}
int pooh_turn(int n)
{
    int i;
    if(Pooh[n]==1){return 1;}
    if(Pooh[n]==0){return 0;}
    if(n==0)
    {
        Pooh[n]=0;
        return 0;
    }
    if(n<=A)
    {
        Pooh[n]=1;
        return 1;
    }
    for(i=0;i<Ma;i++)
    {
        if(n==I1[i])
        {
            Pooh[n]=1;
            return 1;
        }
    }

    for(int i=1;n-i>=0&&i<=A;i++)
    {
        if(!piglet_turn(n-i))
        {
            Pooh[n]=1;
            return 1;
        }
    }
    Pooh[n]=0;
    return 0;
}
int piglet_turn(int n)
{
    int i;
    if(Piglet[n]==1){return 1;}
    if(Piglet[n]==0){return 0;}
    if(n==0)
    {
        Piglet[n]=0;
        return 0;
    }
    if(n<=B)
    {
        Piglet[n]=1;
        return 1;
    }
    for(i=0;i<Mb;i++)
    {
        if(n==I2[i])
        {
            Piglet[n]=1;
            return 1;
        }
    }
    for(int i=1;n-i>=0&&i<=B;i++)
    {
        if(!pooh_turn(n-i))
        {
            Piglet[n]=1;
            return 1;
        }
    }
    Piglet[n]=0;
    return 0;
}