Bash game: there are only a bunch of N items, and two people take things from the pile of items in turn, each time at least one, a maximum of M. The final winner
For the Bashi game, consider n = (m + 1) * k + s, that is, if n % (m + 1 )! If it is set to 0, the first accessor only needs to take the s item to ensure the winner.
HDU 1846: bare.
#include<iostream>#include<cstdio>#include<cstring>#include<algorithm>#include<limits.h>typedef long long LL;using namespace std;int t,n,m;int main(){ cin>>t; while(t--) { cin>>n>>m; if(n%(m+1)) cout<<"first"<<endl; else cout<<"second"<<endl; } return 0;}
HDU 2147: Deformation
<pre name="code" class="cpp">#include<iostream>#include<cstdio>#include<cstring>#include<algorithm>#include<limits.h>typedef long long LL;using namespace std;int n,m;int main(){ while(cin>>n>>m) { if(n==0&&m==0) break; if((n-1)%2||(m-1)%2) cout<<"Wonderful!"<<endl; else cout<<"What a pity!"<<endl; } return 0;}
HDU 2149
#include<iostream>#include<cstdio>#include<cstring>#include<algorithm>#include<limits.h>typedef long long LL;using namespace std;int n,m;int num[1100];int main(){ while(cin>>n>>m) { if(n<=m) { for(int i=n;i<=m;i++) printf(i==m?"%d\n":"%d ",i); } else { if(n%(m+1)==0) printf("none\n"); else printf("%d\n",n%(m+1)); } } return 0;}
Wythoff game: There are several items in two stacks. Two people take the same number of items from one or both stacks in turn, and at least one item is required each time, there are no limits on the number of winners. A = K * (1 + sqt (5.0)/2, B = a + k, bringing a = (B-) * (1 + sqt (5.0)/2 ).
HDU 1527
#include<iostream>#include<cstdio>#include<cstring>#include<algorithm>#include<limits.h>#include<cmath>typedef long long LL;using namespace std;int main(){ int a,b; double q; while(cin>>a>>b) { if(a>b) swap(a,b); q=(1+sqrt(5.0))/2; if(a==(int)((b-a)*q)) cout<<0<<endl; else cout<<1<<endl; } return 0;}
Nimm game: There are three stacks of items
Two people take any number of items from a pile in turn, and each time at least one item is required.
We use (a, B, c) to express a certain situation. First, (0, 0) is obviously a singular situation. No matter who faces a singular situation, it will inevitably fail. The second singular situation is (0, n, n). As long as the opponent takes the same number of items, the last result will be (0, 0, 0 ). After careful analysis, (, 3) is also a strange situation. No matter how the opponent gets it, it can be changed to (0, N, N.
HDU 1850:
#include<iostream>#include<cstdio>#include<cstring>#include<algorithm>#include<limits.h>#include<cmath>typedef long long LL;using namespace std;int num[110];int main(){ int n,t; while(cin>>n&&n) { t=0; for(int i=0;i<n;i++) { cin>>num[i]; t=(t^num[i]); } int cnt=0; for(int i=0;i<n;i++) { if((t^num[i])<num[i]) cnt++; } cout<<cnt<<endl; } return 0;}
To be continued ......
Game: bash game wythoff game nimm game)