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. Java中原始数据类型存放位置理解

    原始数据类型的变量存放在栈还是堆,应该由上下文去决定. 如下所示的局部方法中,定义了本地变量a,且为原始数据类型,所以存放在栈中. public void func(){ int a = 3; } 再 ...

  2. FreeMarker与Servlet结合示例

    一.最原始示例 1.引入POM依赖 <!-- https://mvnrepository.com/artifact/org.freemarker/freemarker --> <de ...

  3. session知识点总结

    1.session生成条件是怎样的?是登陆成功才生成?还是请求进来就生成session和sessionid? 答:Tomcat只要进来请求,就会生成session,同一个ip request来源用的都 ...

  4. TransModeler 交通仿真软件

    1.系统概述 TransModeler是美国Caliper公司开发的一个功能强大而操作灵活的交通仿真软件包,广泛适用于各类交通规划和交通仿真建模任务.TransModeler独特之处在于它提供了宏观/ ...

  5. iOS推断当前控制器是否在显示

    当点击一个cell或者button的事件,处理比較耗时,在异步线程中执行中.当子线程得到执行结果时可能不在当前控制器上了.此时我们须要取消子线程后边的事情. 此刻,当得到结果时须要推断是否在当前控制器 ...

  6. 最老程序猿创业开发实训1---Android应用架构之MVC

    我们都知道Android中基本组件是Activity,每一个界面都是一个Activity,自从2.3版本号開始.又添加了Fragment组件,提供了适应于各种屏幕方法.可是因为Android系统仅仅是 ...

  7. android实现跑马灯效果(能够实现两个以上跑马灯)

    本文用了继承自TextView的MarqueeTextView来实现跑马灯效果.原因是,跑马灯效果是须要TextView拥有焦点才会跑动的.而有时候TextView获得焦点会有点耗时,造成要等待一段时 ...

  8. ios4--UIView的常见属性(尺寸和位置)

    // // ViewController.m // 08-UIView的常见属性(尺寸和位置) // // frame:相对于父控件左上角定位 // bounds:改变长宽,左上角是相对于自己 // ...

  9. Spark 机器学习 ---CountVectorizer

    文本特征提取->> CountVectorizer:基于词频数的文档向量 package Spark_MLlib import org.apache.spark.ml.feature.Co ...

  10. 0606-工厂模式、单例模式、DBDA的单例和完整功能

    工厂模式:只要指定类名,就可以据此获取一个该类的对象. 单例模式:某个类,只允许其“创建”出一个对象. 单例的方法:三私一公(一个私有化对象,一个私有化构造方法,一个私有化克隆方法,一个公共方法返回对 ...