Calendar Game

http://poj.org/problem?id=1082

Time Limit: 1000MS   Memory Limit: 10000K
Total Submissions: 4820   Accepted: 2273

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

搜索+DP+博弈
 1 #include <stdio.h>
 2 #include <memory.h>
 3
 4 int isWin[102][13][32];
 5 int maxDay[13] = {0,31,28,31,30,31,30,31,31,30,31,30,31};
 6
 7 int judge(int y, int m, int d)
 8 {
 9     int win;
10
11     if(y > 101 || (y == 101 &&(m > 11 || (m == 11 && d > 4)))) return 1;
12     if(y == 101 && m == 11 && d == 4) return 0;
13     if(isWin[y][m][d] == -1)
14     {
15         win = 0;
16         if(m != 12)
17         {
18             if(d <= maxDay[m+1] || (d == 29 && m == 1 && (y % 4 ) == 0 && y != 0))
19                 if(judge(y, m+1, d) == 0) win = 1;
20         }
21         else if(judge(y+1, 1, d) == 0) win = 1;
22
23         if(win==0)
24         {
25             if(d < maxDay[m])
26                 win = 1-(judge(y, m, d+1));
27             else if(m != 12)
28                 win = 1-(judge(y, m+1, 1));
29             else
30                 win = 1-(judge(y+1, 1, 1));
31         }
32         isWin[y][m][d] = win;
33     }
34     return (isWin[y][m][d]);
35 }
36
37 int main()
38 {
39     int iCase;
40     int m, d, y;
41
42     memset(isWin, 255, sizeof(isWin));
43     scanf("%d", &iCase);
44     while(iCase--)
45     {
46         scanf("%d%d%d", &y, &m, &d);
47         if(judge(y - 1900, m, d) == 1)
48             printf("YES\n");
49         else
50             printf("NO\n");
51     }
52     return(0);
53 }

Calendar Game

时间: 2024-11-08 22:54:08

Calendar Game的相关文章

常用工具类(System,Runtime,Date,Calendar,Math)

一.Sy 一个java.lang包中的静态工具类. 三大字段: static PrintStream err "标准"错误输出流. static InputStream in "标准"输入流. static PrintStream out "标准"输出流. 其他常用方法: 描述系统信息: 获取系统属性信息: static Properties getProperties(): (Properties是Hashtable的子类,也就是Map 的子类

Java API —— Calendar类

1.Calendar类概述  Calendar 类是一个抽象类,它为特定瞬间与一组诸如 YEAR.MONTH.DAY_OF_MONTH.HOUR 等 日历字段之间的转换提供了一些方法,并为操作日历字段(例如获得下星期的日期)提供了一些方法. 2.成员方法      public static Calendar getInstance():初始化,返回子类对象 public int get(int field):返回给定日历字段的值 public void add(int field,int am

Java日期与时间的处理/Date,String,Calendar转换

public class Demo01 { //Java中Date类和Calendar简介 public static void main(String[] args) { long now=System.currentTimeMillis(); System.out.println("now= "+now); Date d1=new Date(now); System.out.println("d1= "+d1); Calendar c1=Calendar.get

java 日期操作,Date、Calendar 操作

java开发中避免不了日期相关操作,这里总结了一些常用方法~ 直接上码: package jse; import java.io.UnsupportedEncodingException; import java.text.ParseException; import java.text.SimpleDateFormat; import java.util.Calendar; import java.util.Date; import java.util.Locale; /**  * 常用日期操

Date、Calendar、DateFormat、SimpleDateFormat、Timer、TimerTask类

类 Date 在 JDK 1.1 之前,类 Date 有两个其他的函数.它允许把日期解释为年.月.日.小时.分钟和秒值. 它也允许格式化和解析日期字符串.不过,这些函数的 API 不易于实现国际化.从 JDK 1.1 开始,应 该使用 Calendar 类实现日期和时间字段之间转换,使用 DateFormat 类来格式化和解析日期字符串. Date 中的相应方法已废弃. Date() 分配 Date 对象并初始化此对象,以表示分配它的时间(精确到毫秒). Date(long date) 分配 D

关于获取某月某日最后一天时Calendar的cal.getActualMaximum(Calendar.DAY_OF_MONTH)的吐槽

例如: 在2017.03.29-31号 新建一个Calendar的単例 设置年:2017 设置月:2 int day = cal.getActualMaximum(Calendar.DAY_OF_MONTH) 得到日期为:3 例如: 在2017.03.01-28号 新建一个Calendar的単例 设置年:2017 设置月:2 int day = cal.getActualMaximum(Calendar.DAY_OF_MONTH) 得到日期为:28 原因: 1.Calendar类当你set的时候

Java:日期类Date与Calendar

怎么获取系统系统时间,通过java? Date now= new Date(); SimpleDateFormat dateFormat=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSSSSSSSS"); String nowFormate= dateFormat.format(now); System.out.println(nowFormate); 输出结果 2017-02-16 20:56:12.000000278 如何获取当前系统是星期

Calendar 对象的使用实例

1.Calendar demo例子 JavaCalendar 类时间操作,示范代码. public class CalendarDemo { private static SimpleDateFormat date_format = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss"); public static void main(String[] args) { //获取calendar实例; Calendar calendar = Calend

转——JAVA中calendar,date,string 的相互转换和详细用法

package cn.outofmemory.codes.Date; import java.util.Calendar; import java.util.Date; public class CalendarDemo { public static void main(String[] args) { Calendar calendar=Calendar.getInstance(); calendar.setTime(new Date()); System.out.println("现在时间

java.util.Calendar简介

java.util.Calendar简介 一般写为:import java.util.Calendar;在开头 然后在中间写上, Calendar cal = Calendar.getInstance(); int year=cal.get(Calendar.YEAR); int month=cal.get(Calendar.MONTH);就可以了: Calendar是一个抽象类,我们无法直接实例化它,它有一个具体子类实体类java.util.GregorianCalendar,这个类实现的就是