【题目】

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. (亲测)设​置​m​y​e​c​l​i​p​s​e​打​开​默​认​工​作​空​间

    亲测一: 1.找到D:\MyEclipse 8.5\configuration\ config.ini 这个文件 2.找到这一行instance.area.default 3.将后面的地址替换为你想要 ...

  2. oracle数据库使用之数据查询入门

    1.在查询过程中使用算术表达式对数据进行运算 student表结构如下: 最后一项salary表示每个人的月薪,我现在想查询每个人的年薪: 2.使用nvl函数处理null值,向表中插入一条数据,该数据 ...

  3. 使用泛型定义一个可重用的Dao

    dao用来和数据库进行交互,一个项目中,可能有用户表,产品表等等,不可能为每一个表都建立一个dao,使用泛型可以实现通吃. UserDao.java public class UserDao < ...

  4. XC通讯录

    XC通讯录基于Android4.4开发的一个手机通讯录,具有手机拨号,添加联系人,查看联系人,管理编辑联系人,智能查找联系人,删除及批量删除,备份/还原数据,以及手机联系人导入等功能,界面简洁美观,欢 ...

  5. 让图片在DIV中垂直居中

    window.onload=function(){ var img = document.getElementById("imgdiv"); var div = document. ...

  6. 洛谷 P1731 生日蛋糕

    /*洛谷 1731 生日蛋糕 傻傻的-1 T成了傻逼*/ #include<cstdio> #include<iostream> #include<cmath> # ...

  7. CSS中Position属性

    也许你看到这个标题觉得很简单,确实这是一篇关于CSS中Position属性基础知识的文章,但是关于Position的一些细节也许你不了解. 1.简介 position有五个属性: static | r ...

  8. 解决Visual Studio 找不到报表控件、rdlc中文乱码

    找回报表控件 运行安装程序中的 ..\packages\Reporting Services\RVAddon.msi 工具栏,右键选择ReportViewer,注意选择的版本 如果不能编辑报表文件(. ...

  9. 无法加载协定为“ServiceReference1.ReportWsSoap”的终结点配置部分,因为找到了该协定的多个终结点配置。请按名称指示首选的终结点配置部分。

    前言 引用websevice时,有时会出现如下错误: 异常详细信息: System.InvalidOperationException: 无法加载协定为“ServiceReference1.Repor ...

  10. 一个library,相当于一个rootfolder

    picLib.RootFolder.SubFolders 操作library的方式:                         SPList oList = web.Lists[ListName ...