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. Android基础新手教程——4.3.2 BroadcastReceiver庖丁解牛

    Android基础新手教程--4.3.2 BroadcastReceiver庖丁解牛 标签(空格分隔): Android基础新手教程 本节引言: 上节我们对BroadcastReceiver已经有了一 ...

  2. Unix网络编程之环境搭建

    环境搭建 在尝试UNP书上的样例时,会由于找不到"unp.h"等问题无法编译成功.因此在学习之前须要先搭建好编译环境. 步骤 <1>下载  UNIX网络编程源码unpv ...

  3. xml Data Type Methods in sql server

    nodes() Method (xml Data Type) https://docs.microsoft.com/en-us/sql/t-sql/xml/nodes-method-xml-data- ...

  4. 如何测试WCF Rest

    使用SoapUI 1.新建一个rest项目 2.双击上图中的Request1 查询的时候,Method选择post resource的地方要调整到对应的方法 查询的内容是用json格式发送 查询的的结 ...

  5. JNI 实战全面解析

    项目决定移植一款C++开源项目到Android平台,开始对JNI深入研究. JNI是什么? JNI(JavaNative Interface)意为Java本地调用,它允许Java代码和其他语言写的代码 ...

  6. 技术报告:APT组织Wekby利用DNS请求作为C&C设施,攻击美国秘密机构

    技术报告:APT组织Wekby利用DNS请求作为C&C设施,攻击美国秘密机构 最近几周Paloalto Networks的研究人员注意到,APT组织Wekby对美国的部分秘密机构展开了一次攻击 ...

  7. SpringMVC中JSP取不到ModelAndView的数据原因

    自己搭的项目突然EL表达式取不到值了 不管是用 ${msg} 还是用JSTL的<c:out value="${msg}"/> 都不行 才发现犯了一个平时不会注意的错误 ...

  8. android的HTTP框架之Volley

    Volley是android官方开发的一个HTTP框架,简化了利用java中原生的HTTP操作API-HttpURLConnection和HttpClient的操作. 一.首先是Volley的简单使用 ...

  9. df---显示磁盘分区使用空间

    df命令用于显示磁盘分区上的可使用的磁盘空间.默认显示单位为KB.可以利用该命令来获取硬盘被占用了多少空间,目前还剩下多少空间等信息. 语法 df(选项)(参数) 选项 -a或--all:包含全部的文 ...

  10. 使用Xcode的Targets来管理开发和生产版本的构建

    如何创建一个新的Target 如何在Xcode中创建一个开发的target?我使用示例项目“todo”引导您一步一步完成整个过程..您也可以使用自己的项目并按照步骤: 1. 在项目的导航面板进入项目设 ...