Portal: Windy and Mercury-Mercury Games 1
Test instructions: On a chessboard composed of N*m, the K Knight is placed on the board of each knight (Xi,yi), indicating the first XI line, the Knight row if the current position is (x, y), a step can go to the position of
(x-2,y-1)
(x-2,y+1)
(x-1,y-2)
(x+1,y-2)
Two people, each move a knight, at the same time can have more than one knight in the same lattice, who can not move who loses now given the initial chess face, ask the initiator whether there is a winning strategy?
Analysis: The K Knight as a K-game, and then find the K game of the SG value, and then the problem into a K heap stone, each heap has sg[i] a stone, the initiator can choose a heap to take 1~sg[i] a stone, take the final stone people win, it becomes the naked Nim game, All SG values are different or judged to be 0.
#include <cstdio>#include<cstring>#include<algorithm>#defineN 110using namespacestd;intn,m,k;intSg[n][n];intdx[]={-2,-2,-1,1};intdy[]={-1,1,-2,-2};BOOLJudgeintAintb) { returna>=0&&a<n&&b>=0&&b<m;}intDfsintXinty) { if(~sg[x][y])returnSg[x][y]; intvis[5],temp; memset (Vis,false,sizeof(VIS)); for(intI=0;i<4; i++) { inta=x+dx[i],b=y+Dy[i]; if(!judge (A, B))Continue; if((Temp=sg[x][y]) ==-1) temp=Dfs (A, b); Vis[temp]=1; } for(intI=0;i<5; i++) { if(Vis[i])Continue; returnsg[x][y]=i; }}intMain () { while(SCANF ("%d%d%d", &n,&m,&k) >0) {memset (SG,-1,sizeof(SG)); for(intI=0; i<n;i++) for(intj=0; j<m;j++) if(sg[i][j]==-1) DFS (I,J); intx,y,flag=0; while(k--) {scanf ("%d%d",&x,&X); if(Sg[x][y]) flag=1; } if(flag) puts ("Yes"); ElsePuts"No"); }}
View Code
SCU 3132 (game)