【题目】

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. Java基础知识强化之集合框架笔记62:Map集合之HashMap嵌套HashMap

    1. HashMap嵌套HashMap  传智播客          jc    基础班                      陈玉楼  20                      高跃   ...

  2. Android(java)学习笔记194:ListView编写步骤(重点)

    1.ListView在我们的手机android编写程序中使用是十分广泛的,比如如下图中 短信 和 手机设置 都是ListView的效果: 手机设置:             短信:    2.正因为这 ...

  3. 科讯CMS V9标签清单

    全新整理V9标签清单 ====================网站通用标签============== {$GetSiteTitle} 显示网站标题 {$GetSiteName} 显示网站名称 {$G ...

  4. 佛主保佑,永无bug

    /*                    _ooOoo_                   o8888888o                   88" . "88      ...

  5. Nico Game Studio 2.设置页面读写 纹理载入与选择

    进度十分之慢... 配置读写一样采用之前写的自动绑定的方法: 分享一下代码: SetControl是把数据写到control上的. SetObject是把数据写到对象上 GetData是从控件读取数据 ...

  6. WinEdt打开UTF-8文件乱码问题——ctex[转]

    原来这么简单,mark一下! [转自:http://fstang.diandian.com/post/2012-04-17/40030401020] 其实这个问题网上文章已经有一大堆了...我只是记录 ...

  7. 第1条:了解Objective-C 语言的起源

    1.OC语言是由Smalltalk演化而来.该语言使用“消息结构” 而 非“函数调用”. 使用“消息结构”的语言,其运行时所执行的代码由运行环境来决定: 编译器不需要关心接收消息的对象是什么类型,只在 ...

  8. 利用c++操作XML,主要是内部循环方法的使用

    本文主要分享的是循环方法的使用,设置XML节点属性,用了3种循环方法. XML文件: <?xml version='1.0' encoding='utf-8' ?><root> ...

  9. 批量缩放PNG图片.

    最近需要缩放N多图片, 找遍了互联网也没有找到方便使用的批量缩放工具.. 趁着周末写一个练手.. #include <iostream> #include <vector> # ...

  10. USACO 2.2 Subset Sums 集合(subset)

    Description 对于从1到N的连续整集合,能划分成两个子集合,且保证每个集合的数字和是相等的.举个例子,如果N=3,对于{1,2,3}能划分成两个子集合,他们每个的所有数字和是相等的: {3} ...