Calendar GameTime
limit:5000/1000 MS (java/others) Memory limit:65536/32768 K (java/others)
Total submission (s): 3097 Accepted Submission (s): 1809
Problem Descriptionadam 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.
Inputthe 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.
Outputprint 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
Sample Output
Sourceasia 2001, Taejon (South Korea)
Recommendwe carefully selected several similar problems for you:1517 1404 2147 1524 1729
Game.
Into the odd and even game
Discussion area This explanation is good:
Tell me why this question is:
1. Consider the sum of the month and day as a number, sum= (M + D), where M is the month and D is the date.
Is it obvious that sum is either an odd number or an even number, or is it an odd or even number after a change?
There are three kinds of changes in sum:
(1) m + (d + 1) is the date plus one, and does not exceed this month's date, after the change is odd.
(2) (M + 1) + D i.e. month plus one (December each day is available to January Day), after the change is odd.
(3) (M + 1) + 1 is the date plus one, but beyond the date of the month, after the change does not know whether it is odd or even.
It is known from the above (1) (2) (3) that if sum is even and (1) or (2) feasible, then sum must still be an even number.
If sum is only a change (3), then the M and d of this sum can only be as follows:
(m,d) ={(1,31) (3,31) (5,31) (8,31)}.
If sum is an even number and only changes (3) are feasible, then the M and d of such sum can only be as follows:
(m,d) ={(1,31) (3,31) (5,31)}. To make ((M + 1) + 1) = (M + 2) an odd number, the
M must be an odd number, and obviously all M of {(1,31) (3,31) (5,31)} are odd, that is, if sum is even and
Only if the change (3) is feasible, the sum changes to an odd number.
So we can get the following conclusions:
If sum is even, then a change can always make sum odd.
2. If sum is odd, can it still be odd after a change?
Because of the three variations of Sum, (1) (2) makes the sum change to an even number, so that it remains an odd number to satisfy
Obviously, we can only hope for change (3). and the Change (3) of the (M,D) can only be as follows:
(m,d) ={(1,31) ((2,28) or (2,29) (Leap Year)) (3,31) (4,30)
(6,30) (7,31) (8,31) (9,30) (10,31) (11,30) (12,31)}.
Since sum is an odd number, the combination of M and d can only be as follows:
(m,d) ={(2,29) (8,31) (9,30) (10,31) (11,30)}. Likewise in order to make (M + 2) an odd number,
Then M must be an odd number, obviously only the M of {(9,30) (11,30)} is odd, i.e. if sum is odd, after a change
After can still be odd (m,d) only {(9,30) (11,30)}.
3. Above fly a lot of saliva, obviously are some bedding, we need and the subject to a perfect docking.
Our goal in this topic is to make Adam (moving first) win, sum = 15 = (11 + 4) of the target State,
The target sum is an odd number, and if the initial data sum is even or {(9,30) (11,30)}, Adam can always
Throw an odd sum (m,d) to Eve. Then Eve will always have to change the odd sum into even sum.
That means Eve can't reach the target state. Conversely, if Adam did not get an even number at first, or {(9,30) (11,30)}
State, then Adam throws the even sum to the eve,eve and gets control. Adam naturally also cannot reach the target state.
One might think that Adam throws the odd sum to Eve, so Eve doesn't know that the odd sum continues to turn odd.
Adam?
For this problem, as long as Adam leeway is possible, because (9,30) the previous state may be {(8,30) (9,29)}.
These two states can be bypassed (9,30), and similarly, they can be bypassed (11,30).
So just decide if you can get to an odd number of states.
#include <stdio.h> #include <math.h> #include <vector> #include <queue> #include <string> #include <string.h> #include <stdlib.h> #include <iostream> #include <algorithm>using namespace Std;int Main () { int t; scanf ("%d", &t); while (t--) { int y,m,d; scanf ("%d%d%d", &y,&m,&d); if ((m+d)%2==0| | m==9| | m==11&&d==30) printf ("yes\n"); else printf ("no\n"); } return 0;}
Copyright NOTICE: This article is the original blogger articles, reproduced please indicate the source.
Hdoj Calendar Game 1079 "Game"