POJ 1082 博弈推规律

Calendar Game
Time Limit: 1000MS   Memory Limit: 10000K
Total Submissions: 5840   Accepted: 2810

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, 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 is simple: from a current date, a player in his/her turn can move either to the next calendar date or the same day of the next month. When the next month does not have the same day, the player moves only to the next calendar date. For example, from December 19, 1924, you can move either to December 20, 1924, the next calendar date, or January 19, 1925, the same day of the next month. From January 31 2001, however, you can move only to February 1, 2001, because February 31, 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 that decides whether, given an initial date, Adam, the first mover, has a winning strategy. 

For this game, you need to identify leap years, where February has 29 days. In the Gregorian calendar, leap years occur in years exactly divisible by four. So, 1993, 1994, and 1995 are not leap years, while 1992 and 1996 are leap years. Additionally, the years ending with 00 are leap years only if they are divisible by 400. So, 1700, 1800, 1900, 2100, and 2200 are not leap years, while 1600, 2000, and 2400 are leap years.

Input

The input consists of T test cases. The number of test cases (T ) is given in the first line of the input file. Each test case is 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 are 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 has 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 11 3 
2001 11 2 
2001 10 3 

Sample Output

YES
NO
NO

题意:从1月1号到11月4号的任意时间开始,谁先到11月4号谁胜利,下一步可以到下一天或者到下一个月的这天,当下个月没这天就只能走下一天。

来自discuss里的思想:

11月4号是月份+天数的和为奇,即和为奇是必败态,一般情况下每一步可以使月份+天数的和奇偶性改变,但是月末的一天例外。下面罗列了所有月末的一天到下月的第一天出现奇偶不变的情况:
2-28 =》3-1(偶=>偶)
4-30 =》5-1(偶=>偶)
6-30 =》7-1(偶=>偶)
9-30 =》10-1(奇=>奇)
11-30 =》12-1(奇=>奇)


显然对结果有改变的有:
1).某一必胜态“只能”转换到另一必胜态(偶=>偶)(对对方来说,到他了,虽然是偶数,但是他的下一步还是只能走到偶数给对方让对方赢,所以即使他是偶数他还是输)
2).某一必败态“可以”转换到另一必败态(奇=>奇)(对自己来说,虽然自己是奇数,但下一步可以走到奇数,让对方来输)(注意这两种情况的下一步都不是走到像这两种特殊情况来说)


而2-28还可以跳转到3-28
而4-30还可以跳转到5-30
而6-30还可以跳转到7-30
因此前面3个不满足1).而后面2个满足2)
所以9-30和11-30可以让对方为奇数为对自己来说就是必胜态,

另外只要不是对手一开始就是9-30和11-30这两个状态,那么己方一定能避免对手走到这两个状态:(即这两个特别的状态不会影响其他状态的胜败情况)
假如对方是状态9-30,则一定是由己方面临9-29/8-30得到,那么己方可以分别走10-29/8-31来避免对方面临9-30.
11-30同理。

#include <iostream>
#include <cstdio>

using namespace std;

int main() {
    int T;
    cin>>T;
    while(T--) {
        int year,month,day;
        cin>>year>>month>>day;
        if(((day+month)%2==0)||((month==9||month==11)&&day==30)) {
           puts("YES");
        }
           else
            puts("NO");
    }
    return 0;
}






原文地址:https://www.cnblogs.com/zhangmingzhao/p/7256630.html