hdu 1079 Calendar Game
2016-02-03 18:41
316 查看
博弈入门题
Calendar Game
Time Limit: 5000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 3468 Accepted Submission(s): 2051
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
Source
Asia 2001, Taejon (South Korea)
Recommend
We have carefully selected several similar problems for you: 1517 1404 1536 1524 1729
/**========================================== * This is a solution for ACM/ICPC problem * * @source:hdu 1079 * @type: * @author: wust_ysk * @blog: http://blog.csdn.net/yskyskyer123 * @email: 2530094312@qq.com *===========================================*/ #include<cstdio> #include<string> #include<cstring> #include<iostream> #include<cmath> #include<algorithm> using namespace std; typedef long long ll; bool dp[2010][13][32]; int nom[2][13]={ {0,31,28,31,30,31,30,31,31,30,31,30,31 },{0,31,29,31,30,31,30,31,31,30,31,30,31 } }; struct Date { int year,month,day; Date(){} Date(int year,int month,int day):year(year),month(month),day(day){} Date getpredate() { int preyear,premonth,preday; if(day==1) { if(month==1) { preyear=year-1;premonth=12;preday=31; } else { preyear=year; premonth=month-1; preday=getpreday_insameyear(year,month,day); } } else { preday=day-1; premonth=month; preyear=year; } return Date(preyear,premonth,preday); } bool isLeapyear(int x) { return x%4==0&&x%100||x%400==0; } int getpreday_insameyear(int year,int month,int day) { return isLeapyear(year)?nom[1][month-1]: nom[0][month-1]; } Date getlongpredate() { int preyear,premonth,preday; if(month==1) { preyear=year-1; premonth=12; } else { preyear=year; premonth=month-1; } preday=day; return Date(preyear,premonth,preday); } bool isvalid() { if( year<1900) return false; int kind=isLeapyear(year)?1:0; if( day>nom[kind][month] ) return false; return true; } }; void work() { dp[2001][11][4]=0; for(Date today=Date(2001,11,4);today.isvalid() ;today=today.getpredate() ) { Date des=today.getpredate(); if(des.isvalid()) { dp[des.year][des.month][des.day]|= !dp[today.year][today.month][today.day]; } des=today.getlongpredate(); if(des.isvalid()) { dp[des.year][des.month][des.day]|= !dp[today.year][today.month][today.day]; } } } int main() { work(); int T,year,month,day; scanf("%d",&T); while(T--) { scanf("%d%d%d",&year,&month,&day); puts(dp[year][month][day]?"YES":"NO"); } return 0; }
相关文章推荐
- php生成图片验证码
- Jenkins进阶系列之——15Maven获取Jenkins的Subversion的版本号
- 【SEDA异步框架】【四】异步框架总体设计与实现
- 格式化代码、风格检查、代码漏洞检查以及UT覆盖率检查
- rabbitmq学习笔记
- 单测中隔离每个case对DB数据操作
- memcached限制以及与reids的比较
- 【大型网站技术架构笔记】(一)演化过程
- Java泛型
- iOS开发:处理多点触摸与手势检测
- 大数据挖掘-中国知网 papers
- Jenkins进阶系列之——14配置Jenkins用户和权限
- 用listener和beanfactoryaware实现bean的动态装载
- ThreadPoolExecutor和CyclicBarrier配合使用可能带来的隐患
- Hibernate使用问题记录
- linux安装mysql客户端问题总结
- Quartz框架使用时候异常原因记录
- Spring依赖配置化管理
- 在linux环境中安装rabbitmq出现的错误
- 【SEDA异步框架】【一】SEDA国内外研究现状