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. Android 第三方应用接入微信平台(2)

    微信平台开放后倒是挺火的,许多第三方应用都想试下,毕竟可以利用微信 建立起来的关系链来拓展自己的应用还是挺不错的,可以节约很多在社交方 面的开销,我最近由于实习需要也在研究这个东西,不过发现网上的相关 ...

  2. core--主线程

    windows的线程是windows可以分配给cpu的最小单元,对window应用程序的管理,最小的管理单位就是线程.那什么是线程?线程其实什么都不是,只是一个概念,没有实体,又看不见.这个概念的定义 ...

  3. UVa 11825 (状压DP) Hackers' Crackdown

    这是我做状压DP的第一道题,状压里面都是用位运算来完成的,只要耐下心来弄明白每次位运算的含义,还是容易理解的. 题意: 有编号为0~n-1的n台服务器,每台都运行着n中服务,每台服务器还和若干台其他服 ...

  4. VS启用IIS调试的方法及可能碰到的问题。

    经常有这种情况, 开发机本地正常, 但是一旦发布到服务上后, 就出现各种问题. 这是由于开发机和服务器环境不一样造成的, 所以开发时要尽可能的模拟真实性.  这时候, VS的这个功能就帮大忙了. 如何 ...

  5. 【英语】Bingo口语笔记(44) - 进餐时的表达

  6. ORACLE clusterware组成

    oracle cluterware是一个单独的安装包,一旦安装部署好后,每个节点上的oracle cluterware会自动启动,oracle cluterware的运行环境由两个磁盘文件,若干后台进 ...

  7. JS模块化编程之AMD规范(转)

    随着网站逐渐变成"互联网应用程序",嵌入网页的Javascript代码越来越庞大,越来越复杂. 网页越来越像桌面程序,需要一个团队分工协作.进度管理.单元测试等等......开发者 ...

  8. DevExpress控件GridView挂下拉控件无法对上值

    下拉控件使用RepositoryItemLookUpEdit,加入如下事件进行处理. repositoryItemLookUpEdit1.CustomDisplayText += new DevExp ...

  9. 获取Request请求的路径信息

    从Request对象中可以获取各种路径信息,以下例子: 假设请求的页面是index.jsp,项目是WebDemo,则在index.jsp中获取有关request对象的各种路径信息如下 String p ...

  10. Dispatcher

    Dispatcher是guava EventBus的事件分发器. Dispatcher是抽象类, 抽象方法: abstract void dispatch(Object event, Iterator ...