Calendar Game

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

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

这题就是很简单的博弈题目。

一天一天分析,可以发现,(天数+月份)是偶数时胜的,奇数为负的。但是有两个特殊的是9月30和11月30,这两个也是胜的。

分析的时候,只要一个一个月去看。就可以很容易得到上述的结论。

#include <string.h>
#include <stdio.h>
#include <algorithm>
#include <iostream>
using namespace std;
int main()
{
int y,m,d;
int T;
scanf("%d",&T);
while(T--)
{
scanf("%d%d%d",&y,&m,&d);
if( (d+m)% == || (m == && d == ) || (m == && d == ) )
printf("YES\n");
else printf("NO\n");
}
return ;
}

以前也写过一个直接PN分析的代码,也可以搞出来。

#include<stdio.h>
#include<string.h>
#include<algorithm>
#include<iostream>
using namespace std; int f[][][];
int days[]={,,,,,,,,,,,,};
bool isleap(int y)
{
if(y%==||(y%!=&&y%==))return true;
return false;
} bool ok(int y,int m,int d)//看是不是合法的日期
{
if(isleap(y)&&m==)
{
if(d<=)return true;
else return false;
}
if(d<=days[m])return true;
else return false;
} int solve(int y,int m,int d)
{
if(f[y][m][d]!=-)return f[y][m][d];
if(y==&&m==&&d==)return f[y][m][d]=; if(y>)return f[y][m][d]=;
else if(y==&&m>) return f[y][m][d]=;
else if(y==&&m==&&d>)return f[y][m][d]=; int ty,tm,td;
ty=y;
tm=m;
td=d; if(isleap(y)&&m==)
{
td++;
if(td==)
{
tm=;
td=;
}
}
else
{
td++;
if(td>days[tm])
{
td=;
tm++;
if(tm>)ty++,tm=;
}
}
if(solve(ty,tm,td)==)return f[y][m][d]=; ty=y;
tm=m;
td=d;
tm++;
if(tm>)ty++,tm=;
if(ok(ty,tm,td)&&solve(ty,tm,td)==) return f[y][m][d]=; return f[y][m][d]=; } int main()
{
memset(f,-,sizeof(f));
int y,m,d;
int T;
scanf("%d",&T);
while(T--)
{
scanf("%d%d%d",&y,&m,&d);
if(solve(y,m,d))printf("YES\n");
else printf("NO\n");
}
return ;
}

HDU 1079 Calendar Game(简单博弈)的更多相关文章

  1. HDU 1079 Calendar Game(博弈找规律)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1079 题目大意:给你一个日期(包含年月日),这里我表示成year,month,day,两人轮流操作,每 ...

  2. HDU 1079 Calendar Game (博弈)

    Calendar Game Time Limit: 5000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Tot ...

  3. HDU 1079 Calendar Game(规律博弈)

    题目链接:https://cn.vjudge.net/problem/HDU-1079 题目: Adam and Eve enter this year’s ACM International Col ...

  4. HDU 1079 Calendar Game 博弈

    题目大意:从1900年1月1日 - 2001年11月4日间选择一天为起点,两个人依次进行两种操作中的任意一种,当某人操作后为2001年11月4日时,该人获胜.问先手是否获胜 操作1:向后移一天 操作2 ...

  5. HDU 1079 Calendar Game (博弈或暴搜)

    题意:给定一个日期,然后 A 和 B 双方进行操作,谁先把日期变成2001年11月04日,将获胜,如果超过该日期,则输了,就两种操作. 第一种:变成下一天,比如现在是2001.11.3 变成 2001 ...

  6. Hdu 1079 Calendar Game

    Problem地址:http://acm.hdu.edu.cn/showproblem.php?pid=1079 一道博弈题.刚开始想用判断P点和N点的方法来打表,但无奈不知是哪里出错,总是WA.于是 ...

  7. hdu 1846 Brave Game 简单博弈

    Problem Description 十年前读大学的时候,中国每年都要从国外引进一些电影大片,其中有一部电影就叫<勇敢者的游戏>(英文名称:Zathura),一直到现在,我依然对于电影中 ...

  8. HDU 1079 Calendar Game (博弈论-sg)

    版权声明:欢迎关注我的博客,本文为博主[炒饭君]原创文章.未经博主同意不得转载 https://blog.csdn.net/a1061747415/article/details/32336485 C ...

  9. hdu 1079 Calendar Game sg函数 难度:0

    Calendar Game Time Limit: 5000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Tot ...

随机推荐

  1. SQL group by分组查询(转)

    本文导读:在实际SQL应用中,经常需要进行分组聚合,即将查询对象按一定条件分组,然后对每一个组进行聚合分析.创建分组是通过GROUP BY子句实现的.与WHERE子句不同,GROUP BY子句用于归纳 ...

  2. [转帖]在RDLC中使用外部图片

    原文链接:http://blog.csdn.net/rock870210/article/details/4559962 在RDLC中使用外部图片 2009-09-16 19:08 3416人阅读 评 ...

  3. php实现一致性哈希算法

    <?php//原理概念请看我的上一篇随笔(http://www.cnblogs.com/tujia/p/5416614.html)或直接百度 /** * 接口:hash(哈希插口).distri ...

  4. HDU2028 Lowest Common Multiple Plus

    解题思路:最近很忙,有点乱,感觉对不起自己的中国好队友.   好好调整,一切都不是问题,Just do it ! 代码: #include<cstdio> int gcd(int a, i ...

  5. 【英语】Bingo口语笔记(21) - 表达“请客吃饭”

  6. Android中Bitmap, Drawable, Byte,ID之间的转化

    Android中Bitmap, Drawable, Byte,ID之间的转化 1.  Bitmap 转化为 byte ByteArrayOutputStream out = new ByteArray ...

  7. Spring的5种通知

    1.前置通知  Before advice Advice that executes before a join point, but which does not have the ability ...

  8. oracle数据库重建EM

    首先直接在文本控制台执行: [emca不像dbca.netca一样会出现图形化的界面,而是通过文本的交互式操作来完成重新配置]   emca -config dbcontrol db -repos   ...

  9. zoj 3690 Choosing number

    题意    就是说给你 N 个人站成一排,现在每个人都可以选择 1-M 中间的任意一个数字,相邻的两个人数字相同,则他必须是是 >  K 的  问方案总数: 方法    先求出递推式,然后用矩阵 ...

  10. Android 程序员必须掌握的三种自动化测试方法

    在日常的开发中,尤其是app开发,因为不像web端那样 出错以后可以热更新,所以app开发 一般对软件质量有更高的要求(你可以想一下 一个发出去的版本如果有重大缺陷 需要强制更新新客户端是多么蛋疼的事 ...