Hdu 1730 Northcott Game Nim game ~ ~

Source: Internet
Author: User

Northcott GameTime limit:1000/1000 MS (java/others) Memory limit:32768/32768 K (java/others)
Total submission (s): 2936 Accepted Submission (s): 1277


Problem Description Tom and Jerry are playing a Northcott game, but Tom always loses, so he doubts if the game has some kind of winning strategy, depressed Tom now to you for help, can you help him?
The rules of the game are this:
, the game is performed on a chessboard of n rows m (1≤n≤1000 and 2≤m≤100) with one sunspot (black) and one white (white) per line. The black party first, each time the player can move any one of their own pieces to the same line of any one space, of course, the process is not allowed to cross the enemy pieces of the line. The two sides move until one party is unable to move, and the player who moves the last step wins. Tom always goes down first (black). Figure 1 is an initial situation, figure Two is Tom moved a piece after the situation (the first row of sunspots left two steps).



Figure 1



Figure 2

Input data has multiple groups. The first behavior for each set of data is two integers n and m, separated by a space. Then there are n rows, with two numbers per line Ti,ji (1≤ti, ji≤m) representing the number of columns Tom and Jerry have in the row.
   Note: There are an indefinite number of blank lines between the test data for each group. You have to deal with the end of the file.

Output one line of your results for each set of test data. If Tom has a winning strategy in the current situation, output "I win!", otherwise output "bad luck!".
Sample Input
3 64 51 21 23 64 51 31 2

Sample Output
Bad luck! I win!
The value of the SG function shows that the value of the SG function is the absolute minus 1 of the distance of the two pieces. In fact, this is understandable, because we see when two pieces adjacent to the time, is already a must be defeated. Code:
#include <stdio.h> #include <stdlib.h>int main () {int n, m, while (~SCANF ("%d%d", &n,&m)) {int sg = 0; for (int i = 0; i < n; ++i) {int x, y; scanf ("%d%d", &x,&y), SG ^= ABS (x-y)-1;} if (sg==0) puts ("Bad luck!"); Elseputs ("I win!");} return 0;}

with June

Hdu 1730 Northcott Game Nim game ~ ~

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.