原题链接:http://poj.org/problem?id=1082

Calendar Game

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

题解

有一个很简单的思路,我们从2001.11.04倒推,每次可以向后推1天或1个月,通过前面的状态确定当前日期是必胜还是必败,但是有大月小月、闰年平年的影响,推的非常难受,然后POJ上的dalao推出了一个非常妙的结论:

证明如下:

代码
#include<cstdio>
using namespace std;
int y,m,d;
void in()
{scanf("%d%d%d",&y,&m,&d);}
void ac()
{if((m+d)%2==0){printf("YES\n");return;}if(d==30&&(m==9||m==11)){printf("YES\n");return;}printf("NO\n");
}
int main()
{int T;scanf("%d",&T);for(int i=1;i<=T;++i)in(),ac();return 0;
}

POJ1082 Calendar Game相关推荐

  1. Java Calendar.add()方法的使用,参数含义。指定时间差。

    cal.add()方法中的参数含义: 第一个参数如果是1则代表的是对年份操作,2是对月份操作,3是对星期操作,5是对日期操作,11是对小时操作,12是对分钟操作,13是对秒操作,14是对毫秒操作. 第 ...

  2. java calendar与date_Java中date和calendar的用法

    获取现在系统的时间和日期看起来是一件非常神奇的事情,但是当使用date和calendar之后发现仍然非常神奇. 1.date 使用date日期之前需要导入包: import java.text.Sim ...

  3. Calendar如何只显示“一、二、三...日”,不显示“星期”

    秋水无恨 asp.net Calendar DayNameFormat Globalization DayNames http://www.csdn.net/develop/Read_Article. ...

  4. 【JavaSE】day03_Date、SimpleDateFormat、Calendar、Collection

    [JavaSE]day03_Date.SimpleDateFormat.Calendar.Collection 1.Date及其经常使用API 1)JAVA 中的时间 Java中的时间使用标准类库的D ...

  5. Calendar类点点滴滴积累

    为什么80%的码农都做不了架构师?>>>    set(f, value) 将日历字段 f 更改为 value.此外,它设置了一个内部成员变量,以指示日历字段 f 已经被更改.尽管日 ...

  6. php学习,一个简单的Calendar(2) 一个简单的活动页面

    有了前面的基础,后面就是将页面展示出来. 预览图如下:1号和31号分别有活动,会一并显示出来 这里需要搞定几个问题,一个就是数据库的连接,我们用\sys\class\class.db_connect. ...

  7. EBS form日历可选范围设置(calendar.setup )介绍

    Calendar是Template提供给我们的standard object.可以使我们方便的为日期型字段提供日期的选择列表. form中设置日历方法: 1. 为日期型字段指定LOV(ENABLE_L ...

  8. python中,time、calendar、datetime

    原文链接: python中,time.calendar.datetime-MakeDreamsFactory-51CTO博客 https://blog.51cto.com/14094286/23246 ...

  9. 使用java的Calendar对象获得当前日期的上几个度开始、结束时间

    思路: 先获得当前季度的开始和结束日期,在当前日期的基础上往前推3个月即上个季度的开始和结束日期 /*** @param flag true:开始日期:false:结束日期* @return*/pub ...

  10. WordPress Editorial Calendar插件权限安全绕过漏洞

    漏洞名称: WordPress Editorial Calendar插件权限安全绕过漏洞 CNNVD编号: CNNVD-201302-369 发布时间: 2013-02-22 更新时间: 2013-0 ...

最新文章

  1. Request.ServerVariables获取环境变量
  2. ext-4.2之grid的高级应用:增删改查!
  3. [云炬创业学笔记]第一章创业是什么测试7
  4. Linux学习笔记04
  5. sohu读博——周忆清
  6. 小猿圈之java文件重命名
  7. 读书笔记--云边有个小卖部
  8. Linux 下 Weblogic 的安装 、配置以及发布
  9. Qtum DGP 分布自治协议技术详解
  10. 自制汉字字库,识别汉字(三)(汉字篇)
  11. QQ浏览器网页版微信抓包和IPAD微信抓包 Wireshark
  12. caffe学习之conver_imageset.bin的使用方法,caffe下图片转lmdb格式类型数据总结
  13. Python requests模块详解
  14. VBA实现为Excel中自定义名称的单元格添加批注
  15. WordPress安装搭建详细教程—零基础掌握网站如何搭建
  16. 拓嘉辰丰:拼多多差异化运营,做特色店铺
  17. mysql中vlookup函数_VLOOKUP函数的使用方法(入门级)
  18. 修复损坏的gz或tar.gz压缩文件之方法篇
  19. 机器人控制系统的主要功能和特点
  20. 生物信息百Jia软件(十七):flash

热门文章

  1. 均匀带电直线外一点的场强
  2. java添加录音,大家说说java程序里怎么插入视频和音频啊
  3. 西门子S7系列中间人攻击:PLC探测和流量分析(二)
  4. java类加载器用途_对于java类加载器的认识(2)
  5. linux挂载硬盘不适合重启,Linux分区g挂载目录不重启挂载硬盘
  6. mysql根据不同的值查询不同的字段_sql根据一个字段不同值查询不同表中的一个字段...
  7. facade层,service 层,domain层,dao 层设计
  8. Java容器---List
  9. 一起写框架-控制反转(Ioc)概述(二)
  10. 面向对象编程(三)——程序执行过程中内存分析