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. B/S 和 C/S

    B/S最大优势为客户端免维护,适用于用户群庞大,或客户需求经长发生变化的情况. C/S功能强大,可以减轻服务器端压力,如果用户的需求特别复杂,用C/S. 全面: Client/Server是建立在局域 ...

  2. R语言将5位数字日期转为正常日期

    R语言中用double表示日期,即从1970-1-1距离给定日期的天数,将5位数字日期转为正常日期格式的方法 as.Date(16543,origin='1970-1-1')

  3. 信息熵 Information Theory

    信息论(Information Theory)是概率论与数理统计的一个分枝.用于信息处理.信息熵.通信系统.数据传输.率失真理论.密码学.信噪比.数据压缩和相关课题.本文主要罗列一些基于熵的概念及其意 ...

  4. mysql添加用户和用户权限

    Mysql添加用户使用可以对mysql数据库用户表有操作权限的用户名登陆mysqlinsert into user(Host,User,Password) values('%','name','pas ...

  5. 【转】C# 委托的介绍(delegate、Action、Func、predicate)

    委托是一个类,它定义了方法的类型,使得可以将方法当作另一个方法的参数来进行传递.事件是一种特殊的委托. 1.委托的声明 (1). delegate delegate我们常用到的一种声明 Delegat ...

  6. SmartGit STUDY

    Git Concepts This section helps you to get started with Git and gives you an understanding of the fu ...

  7. css3.0新属性效果在ie下的解决方案(兼容性)

    css3.0增加的新属性,如投影.渐变.旋转.圆角等等!这些新标准属性在ie6.ie7.ie8浏览器版本里得不到很好的支持,相信ie以后的新版本也会支持这些新属性的.目前ie6.ie7.ie8浏览器不 ...

  8. bzoj1391 最大权闭合子图(also最小割、网络流)

    一道裸的最小割的题,写一下只是练练手. 表示被卡M,RE不开心.一道裸题至于吗? 再次复习一下最大权闭合子图: 1.每一个点若为正权,与源点连一条容量为绝对值权值的边.否则连向汇点一条容量为绝对值权值 ...

  9. 【LeetCode】70 - Climbing Stairs

    You are climbing a stair case. It takes n steps to reach to the top. Each time you can either climb ...

  10. LeetCode Database: Rank Scores

    Write a SQL query to rank scores. If there is a tie between two scores, both should have the same ra ...