单点时限: 3.0 sec
内存限制: 1024 MB
Nim is a famous take-away game, played as follows. There are $n$ piles of chips containing $x_1, x_2, \ldots, x_n$ chips respectively. (Piles of sizes $5$, $7$, and $9$ make a good game.) Two players take turns moving. Each move consists of selecting one of the piles and removing chips from it. You may not remove chips from more than one pile in one turn, but from the pile you selected you may remove as many chips as desired, from one chip to the whole pile. The winner is the player who removes the last chip.
My comment: This statement is from a course material in CMU. As you may know, this is a famous game with a lot of research done on optimal strategies. And your task, is to beat the computer, or claim that you will lose no matter what effort you have done.
The computer will first tell you about the piles:
Then the game starts. You are the first player.
Each time, you should output two integers $k$ and $v$, meaning that you want to take $v$ chips from the $k$-th pile. $k$ should be between $1$ and $n$ and $v$ should be an positive integer not exceeding the current chip number in the $k$-th pile.
Computer responds in the same way.
If you claim that you are doomed to lose and don’t want to play any more, you should output
-1 -1 so that computer will also quit the game. Your program should also terminate when all the chips have been removed. Computer will never output
-1 -1 – it will fight till the end.
Judgement is as follows:
3 5 7 9 2 7
1 5 3 9
To flush you can use (just after printing an integer and end-of-line):