Calendar Game

Time Limit: 5000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 3628    Accepted Submission(s): 2163

Problem 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. 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
 
想说这道题是个神题(目前这个水平看来)。。。应该有别的思路,但是这个题解的思路我是完全没想到。。。
思路:把month和day看作一个整体sum=month+day,按照题目规则,可以跳到当前日期的下一天,后者跳到下个月对应的当前这天,即month+1或者day+1,那么sum的奇偶性发生变化,11月4日对应的sum为奇数,那么要赢的话,就一直把奇数抛给后者,如果是普通的日期(不是每个月边界)sum为奇数,那么抛出的一定是偶数,sum为偶数,抛出的一定是奇数。边界的话:
(1.31)->(2.1)
(2.28)->(3.28)||(3.1)(平年)
(2.29)->(3.29)||(3.1)(闰年)
(3.31)->(4.1)
(4.30)->(5.1)||(5.30)
(5.31)->(6.1)
(6.30)->(7.1)||(7.30)
(7.31)->(8.1)||(8.31)
(8.31)->(9.1)
(9.30)->(10.1)||(10.30)
(10.31)->(11.1)
(11.30)->(12.1)||(12.30)
(12.31)->(1.1)||(1.31)
其中奇数能抛出奇数的有(9.30)和(11.30),(9.30)的前驱为(9.29)和(8.30),(11.30)的前驱为(10.30)和(11.29),即是说这两个日期是可以被绕过的,那么便有当前位置在这两个日期的人一定可以赢。
综上,若前者初始位置的sum为偶数,则前者一定可以赢,一直让后者走的时候位置在奇数,走后到达偶数;若前者初始位置为(9.30)或(11.30),他也可以抛出奇数。
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std; int main()
{
int n;
scanf("%d",&n);
while(n--)
{
int year,mon,day;
scanf("%d%d%d",&year,&mon,&day);
if((mon+day)%==||((mon==||mon==)&&day==))
printf("YES\n");
else
printf("NO\n");
}
return ;
}

HDU_1079_思维题的更多相关文章

  1. zoj 3778 Talented Chef(思维题)

    题目 题意:一个人可以在一分钟同时进行m道菜的一个步骤,共有n道菜,每道菜各有xi个步骤,求做完的最短时间. 思路:一道很水的思维题, 根本不需要去 考虑模拟过程 以及先做那道菜(比赛的时候就是这么考 ...

  2. cf A. Inna and Pink Pony(思维题)

    题目:http://codeforces.com/contest/374/problem/A 题意:求到达边界的最小步数.. 刚开始以为是 bfs,不过数据10^6太大了,肯定不是... 一个思维题, ...

  3. ZOJ 3829 贪心 思维题

    http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=3829 现场做这道题的时候,感觉是思维题.自己智商不够.不敢搞,想着队友智商 ...

  4. 洛谷P4643 [国家集训队]阿狸和桃子的游戏(思维题+贪心)

    思维题,好题 把每条边的边权平分到这条边的两个顶点上,之后就是个sb贪心了 正确性证明: 如果一条边的两个顶点被一个人选了,一整条边的贡献就凑齐了 如果分别被两个人选了,一作差就抵消了,相当于谁都没有 ...

  5. C. Nice Garland Codeforces Round #535 (Div. 3) 思维题

    C. Nice Garland time limit per test 1 second memory limit per test 256 megabytes input standard inpu ...

  6. PJ考试可能会用到的数学思维题选讲-自学教程-自学笔记

    PJ考试可能会用到的数学思维题选讲 by Pleiades_Antares 是学弟学妹的讲义--然后一部分题目是我弄的一部分来源于洛谷用户@ 普及组的一些数学思维题,所以可能有点菜咯别怪我 OI中的数 ...

  7. UVA 1394 And Then There Was One / Gym 101415A And Then There Was One / UVAlive 3882 And Then There Was One / POJ 3517 And Then There Was One / Aizu 1275 And Then There Was One (动态规划,思维题)

    UVA 1394 And Then There Was One / Gym 101415A And Then There Was One / UVAlive 3882 And Then There W ...

  8. HDU 1029 Ignatius and the Princess IV / HYSBZ(BZOJ) 2456 mode(思维题,~~排序?~~)

    HDU 1029 Ignatius and the Princess IV (思维题,排序?) Description "OK, you are not too bad, em... But ...

  9. cf796c 树形,思维题

    一开始以为是个树形dp,特地去学了..结果是个思维题 /* 树结构,设最大点权值为Max,则答案必在在区间[Max,Max+2] 证明ans <= Max+2 任取一个点作为根节点,那么去掉这个 ...

随机推荐

  1. 18、Java并发性和多线程-饥饿与公平

    以下内容转自http://ifeve.com/starvation-and-fairness/: 如果一个线程因为CPU时间全部被其他线程抢走而得不到CPU运行时间,这种状态被称之为“饥饿”.而该线程 ...

  2. NetCore实现全局异常捕捉统一处理

    做net项目时候,在Global.asax文件中可以通过Application_Error方法全局捕获异常并处理后统一跳转到自定义的错误页面. 下面是我个人在NetCore项目中实现全局捕获异常并统一 ...

  3. scp: useful commands

    Examples Copy the file "foobar.txt" from a remote host to the local host $ scp your_userna ...

  4. 苹果iOS手机后门的”诊断功能论“不攻自破

    7月23日.苹果公司公布公告,题为"iOS:About diagnostic capabilities"("iOS:关于诊断功能").当中声称:iOS offe ...

  5. Oracle OCP之硬解析在共享池中获取内存锁的过程

    转载请注明出处:http://blog.csdn.net/guoyjoe/article/details/38684819 1.获得library cache Latch (1)在父游标的名柄没有找到 ...

  6. 解决Mysql存储中文的问题

    Mysql无法存储中文或者中文乱码,当然是编码的问题.你可以mysql -u root -p进入Mysql命令行环境,然后输入命令查看当前编码格式: mysql> show variables ...

  7. vim随想笔记(1)

    本人是一个vim的狂热粉丝,越是使用vim,越是认为琐碎内容太多,时不时地出现一些自己没有见过的使用方法.命令. 因此准备在博客上用空余时间在阅读<学习vi和vim编辑器>的基础上总结一下 ...

  8. C++中的继承与虚函数各种概念

    虚继承与一般继承 虚继承和一般的继承不同,一般的继承,在目前大多数的C++编译器实现的对象模型中,派生类对象会直接包含基类对象的字段.而虚继承的情况,派生类对象不会直接包含基类对象的字段,而是通过一个 ...

  9. Mysql 存储引擎中InnoDB与MyISAM差别(网络整理)

    1. 事务处理 innodb 支持事务功能,myisam 不支持. Myisam 的运行速度更快,性能更好. 2,select ,update ,insert ,delete 操作 MyISAM:假设 ...

  10. 曼哈顿距离(坐标投影距离之和)d(i,j)=|X1-X2|+|Y1-Y2|.

    曼哈顿距离(坐标投影距离之和)d(i,j)=|X1-X2|+|Y1-Y2|. 我们可以定义曼哈顿距离的正式意义为L1-距离或城市区块距离,也就是在欧几里德空间的固定直角坐标系上两点所形成的线段对轴产生 ...