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
题意是说Adam和 Eve玩日历游戏,在1990年的1月1号到2001年的11月4号之间随机出一个日期,两人轮流移动日期,要求只能往此日期的下一天移动或者下个月的这一天移动(如果下个月没有这一天,则不能移动)如果谁先移动2001年的11月4号,谁就获胜。一下是网上的结题思路,看完之后,跪了。

博弈论题目可以用寻找必败状态的方法解决。

第一个必败状态是2001.11.04。由此可以推出其他任何时间的状态。对于除2001.11.04外的其他任何时间,present状态是由能移动到的下两个next状态决定的(当然有些时间只有一个next状态),比如1924.12.19的状态是由1924.12.20和1925.01.19两个状态决定。如果两个next状态中有一个必败状态,则present状态为必胜状态;如果两个next状态都为必胜状态,则present状态为必败状态。

对于2001年11月的那4天,状态都是交替胜负的。1和3号必胜,2和4号必败。现在考虑10月份,5-31号只有一个next状态,推算可知奇数号状态为必败,偶数号状态为必胜。1-4号状态有两个next状态,推算可知也是奇数号状态为必败,偶数号状态为必胜。也就是说整个10月份奇数号状态为必败,偶数号状态为必胜。

由此我们可以推测如果每个月都是31天的话,那么每天的状态都是相反的,而且相邻的两个月的同一天状态也是相反的。即奇数月的奇数号状态为必胜,偶数号专题为必败;偶数月偶数号状态为必胜,奇数号状态为必败。从数学上说,就是月与号和为偶数的天状态为必胜,为奇数的天状态为必败。显然这个是成立的,可以自己推算一下。

接下来要考虑特殊情况,那几个只有30天的月份。有30号的有4,6,9,11这四个月。对于04.30,next状态有05.01和05.30,显然两个next状态是相反的,所以04.30的状态是必胜的。所以04.30的状态情况符合上面那个结论。06.30同样如此。对于09.30,next状态有10.01和10.30,同样10.01和10.30的状态是相反的,所以09.30的状态为必胜,这不符合上面的结论。但是我们可以证明这只是一种特殊情况,不影响整个结论。按照原来的结论,九月份的奇数号状态为必胜,偶数号状态为必败。现在30号的状态变化了,如果我们能证明29号的状态不会因此发生变化,那么特殊情况就只局限于30号了。09.29号的next状态有09.30和10.29,10.29的状态为必败,所以09.29的状态为必胜,还是符合原来的结论。11.30同样如此。

最后考虑特殊的2月份。如果是闰年的29天,效果和31天一个月是一样的(只要是奇数都一样,哪怕一个月只有一天)。对于非闰年,2月只有28天。其实28天也等同于30天的情况,推算可知02.28和04.30,06.30一样,不影响整个结论。

总结,月与号和为偶数的天状态为必胜,为奇数的天状态为必败。特殊情况为09.30和11.30,这两天的状态也为必胜。

分析转自:http://www.xuebuyuan.com/2028180.html

#include <iostream>
#include <algorithm>
#include <cstring>
#include <cstdio>
#include <vector>
#include <cstdlib>
#include <iomanip>
#include <cmath>
#include <ctime>
#include <map>
#include <set>
using namespace std;
#define lowbit(x) (x&(-x))
#define max(x,y) (x>y?x:y)
#define min(x,y) (x<y?x:y)
#define MAX 100000000000000000
#define MOD 1000000007
#define pi acos(-1.0)
#define ei exp(1)
#define PI 3.141592653589793238462
#define INF 0x3f3f3f3f3f
#define mem(a) (memset(a,0,sizeof(a)))
typedef long long ll;
//1,3,5,7,8,10,12,
//,4,6,,,,,,9,11,
int t,k,m,n;
int main()
{
scanf("%d",&t);
while(t--)
{
scanf("%d%d%d",&k,&m,&n);
bool flag=false,a=false,b=false;
if((m+n)%==) flag=true;
if(m== && n==) a=true;
if(m== && n==) b=true;
if(flag || a|| b) puts("YES");
else puts("NO");
}
return ;
}

POJ 1082 Calendar Game的更多相关文章

  1. POJ 1082 Calendar Game(找规律博弈)

    传送门 以下复制自此处:http://www.xuebuyuan.com/2028180.html 博弈论题目可以用寻找必败状态的方法解决. 第一个必败状态是2001.11.04.由此可以推出其他任何 ...

  2. POJ 1082 Calendar Game 原来这题有个超简单的规律

    万能的discuss.只需要月份和天数同奇同偶即可,9月30和11月30例外 #include <iostream> #include <cstdio> using names ...

  3. 【POJ 1082】 Calendar Game

    [题目链接] http://poj.org/problem?id=1082 [算法] 对于每种状态,要么必胜,要么必败 记忆化搜索即可 [代码] #include <algorithm> ...

  4. Poj Maya Calendar

    http://poj.org/problem?id=1008 Maya Calendar Time Limit: 1000MS Memory Limit: 10000K Total Submissio ...

  5. poj 1079 Calendar Game(博弈论 SG)

    Calendar Game Time Limit: 5000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) To ...

  6. POJ 2080:Calendar

    Calendar Time Limit: 1000MS   Memory Limit: 30000K Total Submissions: 12546   Accepted: 4547 Descrip ...

  7. POJ 2080 Calendar(很水的模拟)

    刚开始一直WA,才发现原来代码中两处减去年份.月份的天数的判断条件用的是>=,虽然最后考虑n=0要退回一天的情况,但还是WA.后来改成>的条件判断,省去了考虑n=0的麻烦,AC. 此题无非 ...

  8. POJ 1082

    #include <iostream> using namespace std; int main() { //freopen("acm.acm","r&qu ...

  9. POJ题目排序的Java程序

    POJ 排序的思想就是根据选取范围的题目的totalSubmittedNumber和totalAcceptedNumber计算一个avgAcceptRate. 每一道题都有一个value,value ...

随机推荐

  1. Unity UGUI——UI基础,Canvas

    主题:画布--Canvas 内容:创建Canvas UI控件的绘制顺序 watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvTXJfQUhhbw==/font/5 ...

  2. Hadoop2.2集群安装配置-Spark集群安装部署

    配置安装Hadoop2.2.0 部署spark 1.0的流程 一.环境描写叙述 本实验在一台Windows7-64下安装Vmware.在Vmware里安装两虚拟机分别例如以下 主机名spark1(19 ...

  3. [Java][log4j]支持同一时候按日期和文件大小切割日志

    依据DailyRollingFileAppender和RollingFileAppender改编,支持按日期和文件大小切割日志.  源文件: package com.bao.logging; impo ...

  4. 4.菜鸟教你一步一步开发 web service 之 axis 客户端创建

    转自:https://blog.csdn.net/shfqbluestone/article/details/37723517 在上个教程中我们创建了一个 axis 服务端的 web service ...

  5. mybatis :与Spring MVC 的集成

    用mybatis与Spring mvc 的方式集成起来,源码在本文结尾处下载.主要有以下几个方面的配置1. web.xml 配置 spring dispatchservlet ,比如为:mvc-dis ...

  6. ajax --- Ajax跨域请求保证同一个session的问题

    我们知道,根据浏览器的保护规则,跨域的时候我们创建的sessionId是不会被浏览器保存下来的,这样,当我们在进行跨域访问的时候,我们的sessionId就不会被保存下来,也就是说,每一次的请求,服务 ...

  7. 如何建立远程桌面连接(XP、Vista、Win7)

    如何建立远程桌面连接(XP.Vista.Win7) 要求: 1:对方即你要连的机器必须要允许远程桌面连接,操作系统一般是winXP(单用户)和win2003server(多用户),具体设置:右击我的电 ...

  8. mysql安装遇到的坑

    安装mysql的三步: mysqld --initialize-insecure mysqld -install net start mysql 中间遇到了坑, 看这篇文章完美的解决了,记录一下 .以 ...

  9. WebAssembly学习(四):AssemblyScript - 结构体系与内置函数

    一.结构体系 1.编译 编译器的结构相对保守. 提供源文件,其文本被标记化并解析为抽象语法树. 这里执行语法级检查. 一旦解析了所有引用的源文件,就构造一个程序并从AST初始化. 在这里进行合理性检查 ...

  10. 昼猫笔记 JavaScript -- 作用域技巧!!

    简单理解 var zm = function (x) { var code = 'bb' return code }; 学过js的老哥们都知道,当这样简单的一个函数进入浏览器,浏览器开始解释代码,会将 ...