Calendar Game POJ - 1082(关于日历的博弈问题)

2022-07-28,,,,

题意:

两个人轮流玩游戏,每个人可以把日期进行转移,转移规则:
1.可以转移到当前日期的下一天。
2可以转移到下个月的这一天。(但是如果下个月没有这一天就不能进行第二种转移)
3.如果A恰好移动到2001.11.4那么A赢,如果移动到2001.11.4之后则输给你初始日期(只能在1900.1.1~2001.11.4)求先移动的人的胜负态

题目:

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

分析:

这是一条简单的规律:一般情况下,月份和日子同奇偶则必胜,否则必败;只有9月30和11月30是例外。

有31天的月份:1,3,5,7,8,10,12
30天的月份:4,6,9,11
奇葩月:2
(1).先从2001.11开始看,这个月只有4天,且每一天只有第一种转移态,那么可以知道1和3号是必胜态,2和4号是必败态,故2001.11月是奇胜
(2).再向前看10月,因为10.5~ 10.31的转移态只有第一种转移态,那么根据推断,10.31为必败,所以5 ~ 31的这些天里偶数的天为必胜态,奇数必败。再看10月的1 ~ 4,对于4来说下一个可以到5和11.4,所以必胜,对于3可以到11.3和10.4所以必败,所以1~4也是偶数必胜奇数必败,故10月是偶数必胜,奇数必败
(3).再看9月,因为9.30可以转到10.1和10.30,为了胜利就选择到10.1故9.30必胜,然后看9.29,可以转到10.29和9.30,同样为了胜利转到10.29,但是再看9.28,无论转到9.29还是10.28都会输,所以9.28是必败,同理9月的1~ 27都是奇胜偶败,加上28,29,30可以得出结论,9月的1~29号都是奇胜偶败,且9.30也为胜。
(4).再看八月,8.31只能到9.1,故为败,8.30可以到8.31故为胜,8.29可以到9.29和8.30,而这两种都会输,所以8.29是输,则1~28号的推理过程相似所以8月是奇败偶胜
这样可以按照相同的方法推出:
(5).7月:奇胜偶败
。。。。。。。
3月:奇胜偶败
再来看2月,如果有29天,则对于2.29可以到3.29和3.1,都会输,所以2.29败,2.28可以到2.29故会赢。所以这种情况是奇败偶胜
如果只有28天,2.28可以到3.28故会赢,2.27可以到2.28和3.27,但都会输,所以这种情况是奇败偶胜
所以2月无论是有29天还是有28天都是奇败偶胜
1月:奇胜偶败
前一年:
12月:奇败偶胜
11月:30可以到12.1,所以胜利,29可以到12.29所以胜利,28可以到29和12.28,但是都会输,所以11月的1~29都是奇胜偶败,且30也会胜利
所以对于任意一个日期(除了9.30和11.30)只要月份+天数为偶数就会胜利,否则失败。

AC代码:

#include<stdio.h>
#include<iostream>
#include<string.h>
#include<algorithm>
using namespace std;
int t,n,m,k;
int main(){
    cin>>t;
    while(t--){
        cin>>n>>m>>k;
        if(m==9&&k==30||m==11&&k==30)
            cout<<"YES"<<endl;
        else if((m+k)%2==0)
            cout<<"YES"<<endl;
        else cout<<"NO"<<endl;
    }
    return 0;
}

本文地址:https://blog.csdn.net/zeng_jun_yv/article/details/109255826

《Calendar Game POJ - 1082(关于日历的博弈问题).doc》

下载本文的Word格式文档,以方便收藏与打印。