Game taking stones (1-10)

Catalog

Take the stone (I) - Bashi

Take the stone (2) - Bashi, NIM

Analysis of stone (III) - PN

Take the stone (IV) - weizov

Stone (V) - PN analysis

Take the stone (6) - NIM

Analysis of stone (7) - PN

Take the stone (VIII) - weizov

Take the stone (9) - anti NIM

Take Shizi (x) - SG

Take the stone (I) - Bashi

Return directory

#include<iostream>
using namespace std;
int main()
{
    int T,n,m;
    cin>>T;
    while(T--){
        cin>>n>>m;
        if(n%(m+1)==0)cout<<"Lose"<<endl;
        else cout<<"Win"<<endl;
    }
    return 0;
}

Take the stone (2) - Bashi, NIM

Return directory

#include<iostream>
using namespace std;
int main()
{
    int T,k,n,m,ans;
    cin>>T;
    while(T--){
        ans=0;
        cin>>k;
        while(k--){
            cin>>n>>m;
            ans^=(n%(m+1));
        }
        if(ans)cout<<"Win"<<endl;
        else cout<<"Lose"<<endl;
    }
    return 0;
}

Analysis of stone (III) - PN

Return directory

#include<iostream>
#include<cstring>
using namespace std;
const int N=1e2+1;
int t[N];
/*
The first to fail
    Different numbers of stone piles are always even;
*/
int main()
{
    int n,flag,a;
    while(cin>>n,n){
        memset(t,0,sizeof(t));
        flag=0;
        while(n--){
            cin>>a;
            t[a]++;
        }
        for(int i=1;i<=100;++i)
            if(t[i]&1){
                flag=1;
                break;
            }
        if(!flag)cout<<"Lose"<<endl;
        else cout<<"Win"<<endl;
    }
    return 0;
}

Take the stone (IV) - weizov

Return directory

#include<iostream>
#include<cmath>
#include<algorithm>
using namespace std;
int main()
{
    int a,b;
    while(cin>>a>>b){
        if(a>b)swap(a,b);
        double k=b-a;
        if(a==(int)(k*(sqrt(5.0)+1)/2))
            cout<<0<<endl;
        else cout<<1<<endl;
    }
    return 0;
}

Stone (V) - PN analysis

Return directory

#include<bits/stdc++.h>
using namespace std;
typedef unsigned long long LL;/*It's the Fibonacci number with 20 digits. long long is 19 digits at most...*/
int main()
{
    LL f[111];
    f[1]=1;
    f[2]=2;
    for(int i=3;i<=92;++i)
        f[i]=f[i-1]+f[i-2];
    LL n;
    while(cin>>n){
        int i;
        for(i=2;i<=92;++i)
            if(f[i]==n)break;
        if(i==93)cout<<"Yes"<<endl;
        else cout<<"No"<<endl;
    }
    return 0;
}

Take the stone (6) - NIM

Return directory

#include<bits/stdc++.h>
using namespace std;
int main()
{
    ios::sync_with_stdio(false);cin.tie();//This card input, scanf can pass
    int T,ans,a,n;
    cin>>T;
    while(T--){
        ans=0;
        cin>>n;
        while(n--){
            cin>>a;
            ans^=a;
        }
        if(ans)cout<<"PIAOYI"<<endl;
        else cout<<"HRDV"<<endl;
    }
    return 0;
}

Analysis of stone (7) - PN

Return directory

#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n;
    while(cin>>n){
        if(n==1||n==2)cout<<"Hrdv"<<endl;
        else cout<<"Yougth"<<endl;
    }
    return 0;
}

Take the stone (VIII) - weizov

Return directory

#include<iostream>
#include<cmath>
#include<algorithm>
using namespace std;
int main()
{
    int a,b;
    while(cin>>a>>b){
        if(!a&&!b)break;
        if(a>b)swap(a,b);
        int t=b-a;
        int k=t*(sqrt(5.0)+1)/2;
        if(k==a)cout<<0<<endl;
        else{
            cout<<1<<endl;
            if(a>=k&&(a-k==b-k-t))cout<<k<<" "<<k+t<<endl;/*That is to see if the difference between (a,b) and (k,k+t) is the same. When a < K, (a,b) will never become (k,k+t)*/
            for(int i=1;i*(sqrt(5.0)+1)/2<=b;++i){
                int A=i*(sqrt(5.0)+1)/2;
                int B=A+i;                                  /*List all required states (A,B)*/
                if(a==A&&b>B)cout<<a<<" "<<B<<endl;         /*Take only one pile, and one point in (a, b) must be the same as (a, b), otherwise you cannot go to the "must fail" state*/
                else if(a>A&&b==B)cout<<A<<" "<<B<<endl;
                else if(a==B&&b>a)cout<<A<<" "<<a<<endl;
            }
        }
    }
    return 0;
}

Take the stone (9) - anti NIM

Return directory

#include<bits/stdc++.h>
using namespace std;
int main()
{
    /*Anti Nimes
      You will lose first:
                Exclusive or result is not 0 and the number of stacks is 1
                The XOR result is 0 and there are more than 1 heaps
    */
    int T,n,a,ans,num;
    cin>>T;
    while(T--){
        ans=num=0;
        cin>>n;
        while(n--){
            cin>>a;
            if(a==0)continue;
            ans^=a;
            if(a>1)num++;
        }
        if((ans&&!num)||(!ans&&num))cout<<"Hrdv"<<endl;
        else cout<<"Yougth"<<endl;
    }
    return 0;
}


Take Shizi (x) - SG

Return directory

#include<cstdio>
#include<cstring>
using namespace std;
const int N=1e3+9;
bool vis[N];
int sg[N],f[N],SG[N],F[N];
void get()
{
    //Second piles
    f[1]=1;
    f[2]=2;
    for(int i=3;i<=15;++i)
        f[i]=f[i-1]+f[i-2];
    sg[0]=0;
    for(int i=1;i<=1000;++i){
        memset(vis,false,sizeof(vis));
        int j=1;
        while(f[j]<=i&&j<=15){
            vis[sg[i-f[j]]]=true;
            ++j;
        }
        j=0;
        while(vis[j])++j;
        sg[i]=j;
    }
    //Fourth piles
    F[0]=1;
    for(int i=1;i<=500;++i)
        F[i]=2*i;
    SG[0]=0;
    for(int i=1;i<=1000;++i){
        memset(vis,false,sizeof(vis));
        int j=0;
        while(F[j]<=i&&j<=500){
            vis[SG[i-F[j]]]=true;
            ++j;
        }
        j=0;
        while(vis[j])++j;
        SG[i]=j;
    }
}
int main()
{

    /*The first reactor: SG[i]=i%3;
      Pile 2: clock
      Stack 3: SG[i]=i;
      Pile 4: clock
      Stack 5: odd, SG[i]=1; even, SG[i]=0;
      The nth reactor: SG[i]=i%(n+1);
    */
    get();
    int n,k,ans,a;
    while(~scanf("%d",&n)){
        if(!n)break;
        k=ans=0;
        while(n--){
            scanf("%d",&a);
            ++k;
            if(k==1)ans^=(a%3);
            else if(k==2)ans^=sg[a];
            else if(k==3)ans^=a;
            else if(k==4)ans^=SG[a];
            else if(k==5)ans^=(a%2);
            else ans^=(a%(k+1));
        }
        if(ans)printf("Yougth\n");
        else printf("Hrdv\n");
    }
    return 0;
}

Tags: iOS

Posted on Mon, 02 Dec 2019 10:55:34 -0500 by fareforce