Tagged with: hdu1079 poj1082 zoj1024 Calendar Game Game
A- Calendar GameTime
limit:MS
Memory Limit:65536KB
64bit IO Form At:%lld &%llu Submit Status Practice ZOJ 1024x768Appoint Description: System Crawler (2015-08-02)
Description
Adam and Eve enter this year ' s ACM International Collegiate programming Contest. Last night, they played the Calendar Game, in celebration of this contest. This game consists of the dates from January 1, 1900 to November 4, 2001, and the contest day. The game starts by randomly choosing a date from this interval. Then, the players, Adam and Eve, make moves in their turn with Adam moving First:adam, Eve, Adam, Eve, etc. There is only one rule for moves and it's simple:from a current date, a player in his/her turn can move either to the NE XT Calendar date or the same day of the next month. When the next month does not has the same day, the player moves is only to the next calendar date. For example, from December, 1924, your can move either to December, 1924, the next calendar date, or January 19, 1925 , the same day of the next month. From January-2001, however, you can move only to February 1, 2001, because February, 2001 is invalid.
A player wins the game when he/she exactly reaches the date of November 4, 2001. If a player moves to a date after November 4, 2001, he/she looses the game.
Write A program This decides whether, given an initial date, Adam, the first mover, have a winning strategy.
For the This game, you need to identify leap years, where February have. In the Gregorian calendar, leap years occur in years exactly divisible by four. So, 1993, 1994, and 1995 is not a leap years, while 1992 and 1996 is leap years. Additionally, the years ending with XX is leap years only if they is divisible by 400. So, 1700, 1800, 1900, 2100, and 2200 is not a leap years, while, and 2400 is leap years.
Input
The input consists of T test cases. The number of test cases (T) is given on the first line of the input. Each test case was written in a line and corresponds to an initial date. The three integers in a line, YYYY MM DD, represent the date of the dd-th Day of Mm-th month in the year of YYYY. Remember that initial dates is randomly chosen from the interval between January 1, 1900 and November 4, 2001.
Output
Print exactly one line for each test case. The line should contain the answer ' YES ' or ' NO ' to the question of whether Adam had a winning strategy against Eve. Since we have t-Test cases, your program should output totally T lines of "YES" or "NO".
Sample Input
3
2001 3
2001 2
2001 10 3
Output for the Sample Input
YES
NO
NO
The main topic is:
Two guys are bored on the eve of regional races, and then play an endless tangled game, and then given a date, you can only move day OR month at a time ....
And if there is no current day in the next one months, you cannot move month, for example, January 31, you can only move day to February 1, and cannot move the moon to February 31, because you understand!
Well, now Adam is starting to YY! Need you to find a winning strategy! (Arrived 2001.11.4 day can not move, unable to move the child paper defeat, more than 2001.11.4 also calculate loses!) )。
Ideas: There is no good way to find the law bar;
Suppose I stand in the state of the initiator
(Note: A-B, if B is all a win state, then a is a must-fail state, if there is a B is a must, then a is the winning state.) )
Victory will be defeated
11.4 11.3
11.2 11.1
10.31 10.30
10.29 10.28
............
10.5 10.4
10.3 10.2
10.1 9.30 (Smart people will choose to transfer to October 1)
9.28 9.29 (Smart people will choose to jump to 10.29)
............
9.4 9.3
9.2 9.1
8.31 8.30(Smart people will choose to transfer to August 31)
8.29 8.28
..........
8.5 8.4
8.3 8.2
8.1 7.31
7.30 7.29
..........
7.4 7.3
7.2 7.1
6.30(Smart people will choose to jump to 7.30)
6.29 6.28
..........
6.5 6.4
6.3 6.2
6.1 5.31
5.30 5.29
..........
5.4 5.3
5.2 5.1
4.30(Smart people will choose to transfer to May 30)
4.29 4.28
..........
4.5 4.4
4.3 4.2
4.1 3.31
3.30 3.29
3.28 3.27
.........
3.4 3.3
3.2 3.1
2.29 2.28
2.27 2.26
..........
2.3 2.2
2.1 1.31
1.30 1.29
1.28 1.27
..........
1.4 1.3
1.2 1.1
12.31 12.30
12.29 12.28
..........
12.3 12.2
12.1 11.30 (Smart people will choose to transfer to December 1)
11.29 (Smart people will choose to transfer to 12.29)
11.28 11.27
11.4 11.3
.....................................................
Whether the month plus one, or the date plus one, have changed the parity, only two special dates September 30, and November 30 exceptions.
Then the target date is November 4, which is odd. If the initial date is even, the first person will win.
Can be seen in the fact that the outcome and the year is not related to say that the year affects only the 29th day of the existence of the February ... And 29 is a must defeat, 28 to win ...
See... To ... Win Point month + date = = Even (minus two exceptions)
Special consideration ...
Reprint Please specify the Source: Looking for Children & stars
#include <stdio.h>int main () { int T; int yy,mm,dd; scanf ("%d", &t); while (t--) { scanf ("%d%d%d", &YY,&MM,&DD); if ((MM+DD)%2==0) printf ("yes\n"); else if (dd==30&& (mm==11| | mm==9)) printf ("yes\n"); else printf ("no\n"); } return 0;}
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
Calendar Game (rule + game)