In game theory, a very important conclusion is as follows:
If the previous status may all be defeated, the current status must be competitive.
If one of the previous states is a winning state, the current State must be a losing state.
Poj 2484 a funny game
In game games, the latter often takes advantage. Except that a can get all the light at a time, B can adopt the same strategy as a in other cases, so that each time the stones are divided into the same two groups, the final winner must be B.
#include <cstdio>#include <cstring>#include <algorithm>using namespace std;int main(){ int n; while(scanf("%d",&n)&&n) { if(n<=2) puts("Alice"); else puts("Bob"); } return 0;}
View code
Poj 2348
Analyze the possible situations of each round (assume a> = B ):
When a-B <= B, the relationship can only be halved, that is, there is only one choice. In this way, the previous status is "win", and the current status is "fail". The previous status is "fail", and the current status is "win.
When a-B> B, assume there is a-xB <= B. There are many options at this time. Consider subtracting (x-1) B from A to arrive at the state, if this state is a defeat state, then the current state is a victory state. If this state is a winning state, the only a-(x-1) B reachable A-xB state is a defeated State, so at this time you can choose to subtract XB from A to win. Therefore, the current status must be competitive.
#include <cstdio>#include <cstring>#include <algorithm>using namespace std;int main(){ int a,b; while(scanf("%d%d",&a,&b)&&!(!a&&!b)) { int c=0; while(1) { if(a<b) swap(a,b); if(a%b==0) break; if(a-b<=b) a=a-b; else break; c++; } if(c%2==1) puts("Ollie wins"); else puts("Stan wins"); } return 0;}
View code
You can participate in a tiered game.
Http://blog.csdn.net/kk303/article/details/6692506
Http://www.cnblogs.com/jiangjing/p/3849284.html
Poj 1704
Step Nim, from right to left, the distance between each two pieces is regarded as a pile of stones, and the distance between the leftmost pieces and 0 is regarded as a pile of stones. In this way, you can perform a nim game on the stones in the odd heap.
#include <cstdio>#include <cstring>#include <algorithm>using namespace std;int main(){ int T; scanf("%d",&T); while(T--) { int n; int p[1005]= {0}; scanf("%d",&n); for(int i=1; i<=n; ++i) scanf("%d",&p[i]); sort(p,p+1+n); int ans=0; for(int i=n; i-1>=0; i-=2) ans=ans^(p[i]-p[i-1]-1); if(ans!=0) puts("Georgia will win"); else puts("Bob will win"); } return 0;}
View code