Nyoj Wythoff Game (brute force enumeration), nyojwythoff
Wythoff Game
Time Limit: 1000 MS | memory limit: 65535 KB
Difficulty: 1
Description
Recently, ZKC learned a great game problem in learning the game-the weizov game.
I believe everyone has learned it? Never learned? No problem. I will tell you about this great game.
There are two piles of stones, which can be different in quantity. The game started with taking stones in turn by two people.
The game stipulates that there are two different methods of getting each time:
First, you can remove any number of stones from any pile;
Second, you can take the same number of stones at the same time in two heaps.
Finally, the winner of all the stones.
What we need to do today is to find the first n defeat states.
What is defeat? For example, we call (a, B) a State. a and B are the numbers left in the two stones respectively. If a = 0, B = 0, we say that this state is mandatory because I can no longer play the game, even if it can be played, it will be defeated, you know, we are all very smart about the game. ()... Are all failed States. What we need to do today is to find the first n failed States. No? Okay!
I will tell you again: assume that the nth mandatory and failed state is (a, B) a, which is the minimum natural number not displayed in the first n-1 mandatory and failed state, and B = a + n. Now you should understand. Well, our task requires the first n failures. It is required that the 0th mandatory defeat States be (0, 0 ).
Input
Multiple groups of data.
Enter n (0 <= n <= 100000) as the number ).
Output
Find the first n failed States as required. The output format is shown in the following example.
Sample Input
3
1
Sample output
)
(0, 0) (1, 2)
Prompt
Note: There is no space in each case.
Ideas:
It is the original definition of the witv game used. Bk = ak + k; ak = (1 + sqrt (5)/2 * k;
Simple brute force enumeration.
The Code is as follows:
<span style="font-size:14px;">#include<stdio.h>#include<math.h>struct sit{int a,b;}s[100100];void f(){s[0].a=s[0].b=0;for(int i=1;i<100100;i++){s[i].a=(1+sqrt(5))*i/2;s[i].b=s[i].a+i;}}int main(){int n;f();while(~scanf("%d",&n)){for(int i=0;i<=n;i++){printf("(%d,%d)",s[i].a,s[i].b);}puts("");}return 0;}</span>