【题目】

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.推进到第二天 2.推进到下个月的这一天。谁到达2001.11.4谁赢,谁超过了谁输。

【分析】

  一开始想到了最暴力的方法,就是递归找状态(应该是能做出来的)。然而看了大神的29行代码后,我方了!!方了!!

  先看看大神的思路:

分析:np问题,我们设月号加日号等于d,对于第二种推进方式,会改变d的奇偶性。(因为月的奇偶变了,日的奇偶没变,和的奇偶就变了)。对于第一种推进方式,如果推进后还在同一个月份,那么会改变d的奇偶性。(因为月的奇偶没变,日的变了,和的奇偶就变了)。第一种推进方式,跨月份的时候,有些会改变,有些不会改变。有31天、29天的月份会变,30天、28天的不会变,其中对于d为偶的情况(2月28,4、6月30)可以利用第二中方式变为奇。

由此可见对于绝大部分情况来说d的奇偶是轮流出现的,最终必败态是11月4日奇态。所有的偶态均可到达奇态,对于d为奇的9、11月30也可以到达奇态。其余奇态只能到达偶态。如果把偶态和9.30和11.30划入集合A,其余划入集合B,那么对于A的所有元素均有办法到达集合B。而B中元素只能到达集合A,无法到达集合B。且11.4属于B。所以,A中元素为必胜,B中为必败。(还需仔细考虑快到2001.11.4的那些日子,幸好也没有出现任何意外)

  我来试着按着他的思路推一遍。

  假设:偶态(日加月为偶数),9.30和11.30为必胜态,其余为必败态。

  我们只要证明:

  ·1、2001.11.4为必败态。(别人给你这个状态相当于别人先一步走到这个状态,你输了)这点显而易见,不需要证明。

  ·2、所有的必胜态都能到达某一必败态。

  ·3、所有的必败态都只能到达必胜态。

  证明2:所有的必胜态都能到达某一必败态。

    1、当为偶态,若能走到下一个月,则能走到必败态。

    2、当为偶态,不能走到下一个月,走到下一天,则能走到必败态。

    3、当为9.30->10.1,当为11.30->12.1

  证明3:所有的必败态(除9.30 11.30的奇态)都只能到达必胜态。

    除了那两天,走到下一天还是下一个月都会是偶态。

  所以假设成立。

代码如下:

 #include<cstdio>
#include<cstdlib>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
#define Maxn 1010 int main()
{
int T;
scanf("%d",&T);
while(T--)
{
int y,m,d;
scanf("%d%d%d",&y,&m,&d);
if((m==||m==)&&d==) printf("YES\n");
else if((m%)==(d%)) printf("YES\n");
else printf("NO\n");
}
return ;
}

[POJ1082]

2016-04-24 15:01:14

  

【POJ1082】Calendar Game (博弈)的更多相关文章

  1. poj1082 Calendar Game (博弈)

    题意是:Adam和Eve两人做游戏,开始给出一个日期,截止日期是2011.11.4,游戏规则如下: 每个人只能将天数增加一天或者将月份增加一天.如果下个月没有这一天,那么只能增加天数. 游戏胜利定义为 ...

  2. Crazy Calendar (阶梯博弈变形)

    2011 was a crazy year. Many people all over the world proposed on 11-11-11, married on 11-11-11, som ...

  3. UVA 1557 - Calendar Game(博弈dp)

    UVA 1557 - Calendar Game 题目链接 题意:给定一个日期,两个人轮流走,每次能够走一月或者一天,问最后谁能走到2001.11.4这个日子 思路:记忆化搜索,对于每一个日期,假设下 ...

  4. uva 1557 - Calendar Game(博弈)

    option=com_onlinejudge&Itemid=8&page=show_problem&problem=4332" target="_blank ...

  5. [POJ1082]Calendar Game

    题目大意: 日历上博弈,从给定的日期,按照下述规则跳转日期: 1.跳到第二天: 2.调到下个月相同的日期(如果没有就不能跳转). 刚刚好跳到2001年11月4日的人胜,跳转时不能跳到2001年11月4 ...

  6. HDU 1079 Calendar Game 博弈

    题目大意:从1900年1月1日 - 2001年11月4日间选择一天为起点,两个人依次进行两种操作中的任意一种,当某人操作后为2001年11月4日时,该人获胜.问先手是否获胜 操作1:向后移一天 操作2 ...

  7. HDU 1079 Calendar Game (博弈或暴搜)

    题意:给定一个日期,然后 A 和 B 双方进行操作,谁先把日期变成2001年11月04日,将获胜,如果超过该日期,则输了,就两种操作. 第一种:变成下一天,比如现在是2001.11.3 变成 2001 ...

  8. LightOJ 1393 Crazy Calendar(博弈)题解

    题意:r*c方格中,每个格子有一定石子,每次移动每格任意数量石子,只能向下或者向右动一格,不能移动为败 思路:显然是Nim,到右下曼哈顿距离为偶数的不用管,因为先手动一下后手动一下最后移到右下后还是先 ...

  9. Light OJ 1393 Crazy Calendar (尼姆博弈)

    C - Crazy Calendar Time Limit:4000MS     Memory Limit:32768KB     64bit IO Format:%lld & %llu Su ...

随机推荐

  1. hdu2026.java字符

    首字母变大写 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Subm ...

  2. vc++ 最小化到托盘的详细实现

    在VC++中,想实现将MFC最小化到系统托盘,需要调用NOTIFYICONDATA类,并注册相应的消息,以下详细讲解如何实现: 1.声明一个NOTIFYICONDATA类,也就是NOTIFYICOND ...

  3. linux下实现redis共享session的tomcat集群

    为了实现主域名与子域名的下不同的产品间一次登录,到处访问的效果,因此采用rediss实现tomcat的集群效果.基于redis能够异步讲缓存内容固化到磁盘上,从而当服务器意外重启后,仍然能够让sess ...

  4. Effective C++ 笔记二 构造/析构/赋值运算

    条款05:了解C++默默编写并调用哪些函数 编译器默认声明一个default构造函数.一个copy构造函数.一个copy assignment操作符和一个析构函数.这些函数都是public且inlin ...

  5. Android studio错误及解决办法

    错误: Cannot launch AVD in emulator. Output: emulator: ERROR: GPU emulation is disabled. Only screen s ...

  6. jquery 如何给新生成的元素绑定 hover事件?

    $("table tr").live({    mouseenter:    function()    {       //todo    },    mouseleave:   ...

  7. [上传下载] C#修改DownLoadHelper上传下载帮助类 (转载)

    点击下载 DownLoadHelper.rar 主要功能如下 /// <summary> /// 输出硬盘文件,提供下载 支持大文件.续传.速度限制.资源占用小 /// </summ ...

  8. Android混淆那些事儿

    博客: 安卓之家 微博: 追风917 CSDN: 蒋朋的家 简书: 追风917 博客园:追风917 # Android混淆 Android混淆是Android开发者经常使用的一种用于代码防止被反编译的 ...

  9. 安装mysql数据库

    http://jingyan.baidu.com/article/f3ad7d0ffc061a09c3345bf0.html

  10. while循环的跳出

    今天在编码时突然产生一个疑问:程序中有一个while循环,循环体执行的是某个附带条件限制的操作.我现在想达到的目的是 => 条件成立,就执行操作,并跳出循环:条件不成立就跳出当次的while循环 ...