Question link: http://acm.hdu.edu.cn/showproblem.php? PID = 1, 2147
A game starts at (1, m) in a matrix of N * m and ends at (n, 1 ); the rule of the game is to go to the left, down, and left, and to the end is the winner.
This is the Bashi game. The self-taught children are still confused about the information they are looking for on the Internet:
You just need to plot the PN state diagram:
P: when the other party wins (or loses)
Point N: when there are n stones, you can win.
There are three rules for Solving P and N.
(1): the final state is P.
(2): According to the game rules, if the first State to reach the current state is N, the current State is P
(3): According to the game rules, if there is at least one P before the current state is reached, the current State is n
/*
* Game Theory: Combined game
* Point to defeat (point to defeat): The previous player called the winning position a point to defeat.
* Winning point (n): The Next player calls the winning position a winning point.
* The attribute of the point to be defeated (winning:
* (1) All endpoints are mandatory (point P );
* (2) from any winning point (N points), at least one method can be used to enter the winning point (P point );
* (3) no matter how you operate, you can only enter the point of victory (n) from the point of defeat (P ).
* The algorithm for this question is obtained from the above attributes:
* Step 1: Mark all endpoints as vertices (point P );
* Step 2: Mark the locations where all the operations can enter the point (point B) as the point B (point N)
* Step 3: If all the operations starting from a certain point can only enter a winning point (point N), mark the operation as a point P );
* Step 4: If you fail to find a new P point in step 3, the algorithm is terminated. Otherwise, step 2 is returned.
* An example is calculated using the preceding algorithm:
* We can convert the problem from (1, 1) to (n, m) (so that we can draw a conclusion)
* N = 8, M = 9
Nnnnnnnnnnn
Pnpnpnpnp
Nnnnnnnnnnn
Pnpnpnpnp
Nnnnnnnnnnn
Pnpnpnpnp
Nnnnnnnnnnn
Pnpnpnpnp
* The initial vertex () is N, so wonderful is output!
* From this example, we can clearly see that when N and m are odd, the initial point () is P.
* Therefore, you only need to judge whether N and m are both odd numbers.
*/
#include<iostream>using namespace std;int main(){int n,m;while(cin>>n>>m,m+n){puts((n%2&&m%2)?"What a pity!":"Wonderful!");}return 0;}