#P9898. 『PG2』猪棋
『PG2』猪棋
Background
The interactive library is extremely smart.
Problem Description
Rules of Pig Chess:
On a board, two players take turns playing Black and White. In each turn, the current player may place two pieces on two different empty positions on the board (ordered). If, when a piece is placed, the four positions all contain pieces of the same color, then the player of that color wins.
You will play as the first player, and you need to defeat the interactive library (playing as the second player) within moves. A solution is guaranteed to exist.
In each round, you may choose two coordinates and to place your pieces. First, you must ensure . Next, you must ensure that no one has ever placed a piece at . If you win at this point, the judging ends and you win. Otherwise, you must also ensure that no one has ever placed a piece at . If you win at this point, the judging ends and you win. Otherwise, the interactive library will return a set of , meaning it places pieces at and . It is guaranteed that and . If the interactive library wins at this point, the judging ends and you lose. Otherwise, it will check whether there are already pieces on the board. If yes, you get a draw; otherwise, it enters your next round.
Input Format
After each round ends, read four integers from standard input, representing the result returned by the judge.
Output Format
At the beginning of each round, output four integers in to standard output, and then flush the buffer.
You may use the following statements to flush the buffer:
- For C/C++:
fflush(stdout); - For C++:
std::cout << std::flush; - For Java:
System.out.flush(); - For Python:
stdout.flush(); - For Pascal:
flush(output); - For other languages, please check the documentation of the corresponding language.
In particular, for C++, when outputting a newline, if you use std::endl instead of '\n', it can also flush the buffer automatically.
Hint
There are test points. In a test point, if you win and in every step you satisfy , you will get points; otherwise, if you win you will get points; if you lose you will get points; if you draw you will get points. The final score is the minimum over all test points.
Reference I/O -point program for this problem:
#include <bits/stdc++.h>
using namespace std;
int n;
int x,y,xx,yy;
signed main()
{
int i,j,k;
n=100;
while(n--)
{
cout<<rand()%1000+1<<' '<<rand()%1000+1<<endl;
cout<<rand()%1000+1<<' '<<rand()%1000+1<<endl;
cin>>x>>y>>xx>>yy;
}
return 0;
}
Translated by ChatGPT 5