Original question:
The game of Spot is played on a NxN board as shown below for N = 4. During the game, alternate players may either place a black counter (spot) in an empty square or remove one from the board , thus producing a variety of patterns. If a board pattern (or its rotation by degrees or degrees) is repeated during a game, the player producing that Pat Tern loses and the other player wins. The game terminates in a draw after 2N moves if no duplicate pattern was produced before then.
Consider the following patterns:
If the first pattern had been produced earlier, then any of the following three patterns (plus one other not shown) would Terminate the game, whereas the last one would not.
Input and Output
Input would consist of a series of games, each consisting of the size of the board, N (2 tex2html_wrap_inline180 n tex2html _wrap_inline180) followed, on separate lines, by 2N moves, whether they is all necessary or not. Each move would consist of the coordinates of a square (integers in the range 1..N) followed by a blank and a character -' indicating the addition or removal of a spot respectively. You may assume this all moves is legal, which is there would never be an attempt-place a spot in an occupied square, nor To remove a non-existent spot. Input would be terminated by a zero (0).
Output would consist of one line for each game indicating which player won and on which move, or that the game ended in a D Raw.
Sample input
2
1 1 +
2 2 +
2 2-
1 2 +
2
1 1 +
2 2 +
1 2 +
2 2-
0
Sample output
Player 2 wins on move 3
Draw
Effect:
(From Lucky Cat)
The game of the Spot is on a NxN board, as shown in the N=4 board. The game is played by two players in exile a stone in an empty lattice, or you can take a piece of stone from the board, the game can be found that the board of the stone on the board will be constantly changing, when a player discharged has been re-existing in the release of the board, he even lost this game (a bureau if the rotation of 90 degrees, 180 degrees, 270-degree is also the same as the agency). If the same layout is not in the 2N step, the draw.
Input
The input will have a number of test materials, the size of the board to the start of N (2 <= n <= 50), then there will be a 2N move way, of course, it is possible that 2N steps have not yet finished, someone won the race. Each column will have a target position, with a + or-to indicate the addition or removal of a stone. You can assume that all the steps are legal, that is, not to take a piece of stone on an empty grid, or to re-place the stone in the same position. The final end of the input will be n=0.
Output
Please output which player wins the race, and at which step wins the match, if the draw is the tie.
#include <bits/stdc++.h>using namespace STD;//fstream in,out; Map<string,bool>MsintN,m;stringSpanstring&SS) {stringT (N,' 0 '); for(intI=1; i<=m;i++) { for(intj=1; j<=m;j++) {intX=j;inty=m-i+1; t[(x1) *m+y-1]=ss[(I-1) *m+j-1]; } }returnt;}voidMove (intAintBCharCstring&SS) {if(c==' + ') ss[m*a+b]=' 1 ';Elsess[m*a+b]=' 0 ';}intMain () {Ios::sync_with_stdio (false);//In.open ("Data.txt");//Out.open ("Input.txt"); while(Cin>>m,m) {n=m*m; Ms.clear ();intans=0, A, B;CharCstringNow (N,' 0 ');stringTmp1,tmp2,tmp3; for(intI=1; i<=m*2; i++) {Cin>>a>>b>>c;if(ans==0) {Move (a1, B-1, C,now);//cout<<now<<endl;Tmp1=span (now);//cout<<tmp1<<endl;Tmp2=span (TMP1);//cout<<tmp2<<endl;Tmp3=span (TMP2);//cout<<tmp3<<endl; if(ms[now]| | ms[tmp1]| | ms[tmp2]| | Ms[tmp3]) ans=i;Elsems[now]=ms[tmp1]=ms[tmp2]=ms[tmp3]=true; } }if(ans==0)cout<<"Draw"<<endl;Else{if(ans%2)cout<<"Player 2 wins on move"<<ans<<endl;Else cout<<"Player 1 wins on move"<<ans<<endl; } }//In.close ();//Out.close (); return 0;}
Answer:
Recently in the completion of the establishment, but still can not stop to do the question ~ Otherwise csdn above perseverance on the small badge will be gone. =_= so I'm going to get UVA above 100 to 199 to do, time enough to do a few difficult.
The topic is very simple, each time with a map recorded before the board can be, when the board rotates to use the matrix rotation formula.
The rotation formula for coordinates is:
(x, y) around (0, 0) clockwise to 90 degrees after coordinates (y,-X)
(x, Y) around (p, q) Clockwise 90 degrees, first move the origin to (p, Q), (X-p, y-q) around (0, 0) rotation 90 degrees after (Y-q, p-x)
Final result (y-q+p, p-x+q)
The clockwise rotation formula of the matrix is added 1 to the coordinate system of Y.
That
(Y-q+p, p-x+q+1)
Since this topic is rotated around the center, the P=Q=N/2
UVA 141 the Spot Game