Logu P2361 yyy Chess _ Simulation

Source: Internet
Author: User
Tags abs
Topic description

Uim recently studied a game called "yyy Chess".
The rule of this game is very simple, that is, there is a a*b chessboard and black-and-white chess pieces, two people take turns in the bottom of the lattice. You can go to black or white, you can change the color, you can go under any place you like, but to meet the following conditions:
1, this position can not have been occupied by other pieces.
2, you are ready to place, up and down a grid range can not have the same color as you prepare the pieces.
3, the first person must be out of sunspots.
When there is no place to put the son, who loses.
Uim pulled you out, I hope you play with him well.
Because you are very busy and reluctant, uim concessions, allowing you to choose the upper or late.
You suddenly have a flash, think of your primary School Olympiad to do a problem: two people sitting on both sides of a table, in turn to put coins on the table, coins can not overlap, who can not put down who lost. It feels a bit like that, so you're going to use this approach.
You know, through some kind of strategy, you must win 100%.
That being the case, let Uim lose a good time.
Input and output formats
Input format:
First line, a,b, two integers, representing the chessboard size
The next few lines, the order of Uim, x_i,y_i,c_i, respectively, indicate position and color, color 1 is black, and 0 is white. Location is 1<=x_i<=a 1<=y_i<=b.
Into the UIM found no place to go, you may cheat, the pieces under the illegal place. In this case, you should also point out that. Of course, Uim also may know that they have lost after the loss. There is no uim to surrender if the game has not been decided.
Output format:
The first line, the choice of the upper or the second, the second step, please output "a", the output "Second".
The next few lines, if you are the first one, please output your first step to dismount. Then respond to each of the uim of the child. Output x_i y_i c_i, meaning is the same as above. You must export the winning dismount, or you will WA this point. If more than one dismount is a winning point, please output a game can be completed as soon as possible dismount.
Before you finish this, please pretend you don't know Uim's next move.
If Uim is cheating, then this line of output "Buwanle" and end the program, the extra input will ignore it.
Input and Output sample
Enter Sample #:
2 2
1 2 1
1 1 1
Output Sample #:
Second
2 1 0
Buwanle
Description
40% data, 2<=a,b<=3
100% data, 2<=a,b<=9 analysis

There is nothing to say about this problem, just clear a rule. That is the principle of central symmetry.
if (a*b) is odd, then there must be a central symmetrical point, then you have to choose the tempo, occupy this center point, otherwise choose the next. And then where the opponent is, then I can certainly find another symmetrical point to put the pieces. That's why we have to occupy the center point.

For color. if (a*b) is odd, then every time you choose a piece of the same color as the opponent, if an even number, then choose a different color with the opponent each piece.

Use your Own (2*3), (3 * 3) of the chessboard simulation to know why, the code

It's like a little messy code. But it's still a.

var num,x,y,z,i,a,b,j:longint;
Pan:array[1..9,1..9]of integer;
function Check (X,y,z:longint): boolean;
var Flag,i,j:integer;
  Begin if (x-1>0) and (Pan[x-1,y]=z) then exit (true);
  if (y+1<=b) and (Pan[x,y+1]=z) then exit (true);
  if (x+1<=a) and (Pan[x+1,y]=z) then exit (true);
  if (y-1>0) and (Pan[x,y-1]=z) then exit (true);
Exit (FALSE);

End
  Begin READLN (A,B);
  For I:=1 to a does for J:=1 to B do pan[i,j]:=-1;
      If Odd (a*b) THEN begin Writeln (' a ');
      Writeln (a div 2+1, ', b div 2+1, ', 1);
      Pan[a Div 2+1,b Div 2+1]:=1;
          While isn't EOF do begin READLN (X,Y,Z);
          Pan[x,y]:=z;
          if (x=0) THEN begin Writeln (' Buwanle ');
                              If check (x,y,z) THEN begin Writeln (' Buwanle '); Halt;end else begin
                              Writeln (a-x+1, ', b-y+1, ', z);
                            Pan[a-x+1,b-y+1]:=z;
        End
 End   end ELSE begin num:=0;
      Writeln (' Second ');
          While isn't EOF do begin READLN (X,Y,Z);
          if (x=0) THEN begin Writeln (' Buwanle ');
          Inc. (NUM);
          if (z=0) and (num=1) THEN begin Writeln (' Buwanle ');
          Pan[x,y]:=z;
                              If check (x,y,z) THEN begin Writeln (' Buwanle '); Halt;end else begin
                              Writeln (a-x+1, ', b-y+1, ', ABS (Z-1));
                            Pan[a-x+1,b-y+1]:=abs (z-1);
        End
    End

End


End.

 Evaluation results: Accepted Score: 100 Date: 2015-10-18 09:28 time: 46ms Memory: 3137kb Click into the record list. Compilation information compiling compilation success result test point #1: Pass the test point.
Score 20, time consuming 0ms, memory 3137kB. Test point #2: Pass the test point.
Score 20, time consuming 0ms, memory 3100kB. Test point #3: Pass the test point.
Score 20, time consuming 0ms, memory 3133kB. Test point #4: Pass the test point.
Score 20, time consuming 31ms, memory 3137kB. Test point #5: Pass the test point.
 Score 20, time consuming 15ms, memory 3133kB.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.