Hdu2873 Bomb Game ----- sg

Source: Internet
Author: User

Bomb Game
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission (s): 353 Accepted Submission (s): 165


Problem Description
John and Jack, two mathematicians, created a game called "Bomb Game" at spared time. this game is played on an n * m chessboard. A pair of integers (p, q) represents the grid at row p, column q. some bombs were placed on the chessboard at the beginning. every round, a player can choose to explode a bomb located at (p, q), and the exploded bomb will disappear. furthermore:

1. if p> 1 and q> 1, the bomb will split up into two bombs located at (u, q) and (p, v), u <p, v <q, u and v are chosen by the player.
2. If p = 1 and q> 1, one new bomb will be produced, located at (p, v), v <q, v can be chosen freely by the player.
3. If q = 1 and p> 1, one new bomb will be produced, located at (u, q), u <p, u can be chosen freely by the player.


If two bombs located at the same position or a bomb located at (1, 1), they will be exploded automatically without producing new bombs.
Two players play in turn, until one player cannot explode the bombs and loses the game.
John always plays first.
Now, we'll give you an initial situation, and you shoshould tell us who will win at last. Assume John and Jack are smart enough, and they always do the best choice.

Input
There are several test cases, each one begins with two integers n and m, 0 <n, m <= 50, represents the number of rows and columns. following by an n * m grid, describing the initial situation, '#' indicates bomb.
The input is terminated by n = m = 0.

Output
For each test case, output one line, the name of the winner.

Sample Input
2 2
.#
..
2 2
.#
.#
0 0

Sample Output
John
Jack

Source
2009 Multi-University Training Contest 8-Host by BJNU

Recommend
Gaojie
 
I have worked hard on this question A. The question 1 is the 0 of the input matrix, that is, the position () is the position of the input matrix (), dizzy, I want to die.
[Cpp]
# Include <iostream>
# Include <cstdlib>
# Include <stdio. h>
# Include <memory. h>
Using namespace std;
Int sg [60] [60];
Char str [60] [60];
Int num [600];
Int dfs (int x, int y)
{
Memset (num,-1, sizeof (num ));
For (int I = 0; I <x; I ++)
For (int j = 0; j <y; j ++)
{
Num [sg [I] [y] ^ sg [x] [j] = 1;
}
For (int I = 0; I ++)
If (num [I] =-1) return I;
}
Int main ()
{
For (int I = 0; I <= 50; I ++)
Sg [0] [I] = sg [I] [0] = I;
For (int I = 1; I <= 50; I ++)
For (int j = 1; j <= 50; j ++)
Sg [I] [j] = dfs (I, j );
Int n, m;
While (scanf ("% d", & n, & m )! = EOF)
{
If (n = 0 & m = 0) break;
Int ans = 0;
For (int I = 0; I <n; I ++)
{
Scanf ("% s", str [I]);
For (int j = 0; j <m; j ++)
{
If (str [I] [j] = '#')
{
Ans ^ = sg [I] [j];
}
}
}
If (ans) puts ("John ");
Else puts ("Jack ");
}
}

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.