Title Link: http://acm.hdu.edu.cn/showproblem.php?pid=1079
The main problem: the main idea, two people Adam and Eve play together, the rules of the game from January 1, 1900 to November 4, 2001, the time period of random selection of the day, by Adam began to take turns to choose, you can choose the day after, you can choose the next month of the day, take turns, The last person to choose November 4, 2001 wins, randomly giving a date and asking Adam if he will win.
Well, see the topic is really frightened, a little do not know where to start the feeling, there is a leap month interference, see other people's analysis to understand that the problem is very simple, can be converted to odd and even problems.
sum = (M + d), where M is the month and D is the date, there are three results for each selection:
1) date plus one, and no more than this month's date, sum = sum + 1 (parity change)
2) month plus one, sum = sum + 1 (parity change)
3) date plus one, over this month's date, sum = Nextm + 1 (parity not necessarily)
For the third case analysis, the last day of the month can be divided into the following four categories:
1) Odd +1 = Odd 9.30 11.30
2) Odd +1 = even 2.29 (LEAP) 6.30 8.31 10.31 12.31
3) Even +1 = even 2.28 4.30
4) Even +1 = odd 1.31 3.31 5.31 7.31
Analysis of the topic, November 4 is odd, the previous choice of the number of even-numbered date, that is, the even-numbered is favourable situation, odd for the situation, the favourable situation of the people will not change their favourable situation, while the disadvantaged people must want to reverse the adverse situation, that is, if Eve is in a disadvantageous situation, He would like to have Adam in a disadvantageous situation through his own choice, and the situation would be only 9.30 and 11.30 days, while those in the dominant situation would inevitably not make the situation into those two dates, so Adam would have to win the initial date as an even number, or 9.30 or 11.30 at the beginning.
A game turns into a parity problem with a special point.
1#include <stdio.h>2 intMain () {3 intT;4 intD, M, y;5scanf"%d",&T);6 for(inti =0; i < T; ++i) {7scanf"%d%d%d",&y,&m,&d);8 if((m+d)%2==0|| (M = =9|| m = = One) && D = = - ) )9Puts"YES");Ten Else OnePuts"NO"); A } -}
HDOJ 1079 Calendar Game