Calendar Game

Time Limit: 5000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)

Total Submission(s): 2519    Accepted Submission(s): 1438

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
 
#include <iostream>
#include <cstdio>
using namespace std; int PN[2010][20][50] , year = 2001 , month = 11 , day = 4;
int mp[13] = {0 , 31 , 30 , 31 , 30 , 31 , 30 , 31 , 31 , 30 , 31 , 30 , 31}; void sub_day(){
if(day == 0){
month--;
if(month == 0){
month = 12;
day = 31;
year--;
}else{
if(month == 2){
if(year%4==0&&year%100!=0||year%400==0) day = 29;
else day = 28;
}else{
day = mp[month];
}
}
}
} bool add_month(int &Y , int &M , int &D){
if(M > 12){
Y++;
M = 1;
return true;
}else{
if(M == 2){
if(Y%4==0&&Y%100!=0||Y%400==0){
if(D > 29) return false;
return true;
}else{
if(D > 28) return false;
return true;
}
}else{
if(mp[M] < D) return false;
return true;
}
}
} int SG(){
int Y = year , M = month+1 , D = day;
if(add_month(Y , M , D)){
if(PN[Y][M][D] == 1) return 0;
}
return 1;
} void initial(){
PN[year][month][day] = 1;
int ty = year , tm = month , td = day;
day--;
while(year >= 1900){
if(PN[ty][tm][td] == 1) PN[year][month][day] = 0;
else PN[year][month][day] = SG();
ty = year , tm = month , td = day;
day--;
sub_day();
}
} int main(){
initial();
int YYYY ,MM, DD ,T;
scanf("%d" , &T);
while(T--){
scanf("%d%d%d" , &YYYY ,&MM, &DD);
if(PN[YYYY][MM][DD]) printf("NO\n");
else printf("YES\n");
}
return 0;
}

poj 1079 Calendar Game(博弈论 SG)的更多相关文章

  1. POJ 2960 S-Nim 博弈论 sg函数

    http://poj.org/problem?id=2960 sg函数几乎是模板题. 调试代码的最大障碍仍然是手残在循环里打错变量名,是时候换个hydra产的机械臂了[超想要.jpg] #includ ...

  2. HDU 1847 Good Luck in CET-4 Everybody! (博弈论sg)

    Good Luck in CET-4 Everybody! Problem Description 大学英语四级考试就要来临了,你是不是在紧张的复习?或许紧张得连短学期的ACM都没工夫练习了.反正我知 ...

  3. HDU.1847 Good Luck in CET-4 Everybody! ( 博弈论 SG分析)

    HDU.1847 Good Luck in CET-4 Everybody! ( 博弈论 SG分析) 题意分析 简单的SG分析 题意分析 简单的nim 博弈 博弈论快速入门 代码总览 //#inclu ...

  4. 【bzoj3576】[Hnoi2014]江南乐 博弈论+SG定理+数学

    题目描述 两人进行 $T$ 轮游戏,给定参数 $F$ ,每轮给出 $N$ 堆石子,先手和后手轮流选择石子数大于等于 $F$ 的一堆,将其分成任意(大于1)堆,使得这些堆中石子数最多的和最少的相差不超过 ...

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

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

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

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

  7. POJ 2425 A Chess Game 博弈论 sg函数

    http://poj.org/problem?id=2425 典型的sg函数,建图搜sg函数预处理之后直接求每次游戏的异或和.仍然是因为看不懂题目卡了好久. 这道题大概有两个坑, 1.是搜索的时候vi ...

  8. (博弈论)hdoj 1079 Calendar Game

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1079 题解:题目大意,两个人Adam和Eve一块儿玩游戏,游戏规则是从1900年1月1日到2001年1 ...

  9. poj 3710 Christmas Game【博弈论+SG】

    也就是转换到树形删边游戏,详见 https://wenku.baidu.com/view/25540742a8956bec0975e3a8.html #include<iostream> ...

随机推荐

  1. 用户空间缺页异常pte_handle_fault()分析--(下)--写时复制【转】

    转自:http://blog.csdn.net/vanbreaker/article/details/7955713 版权声明:本文为博主原创文章,未经博主允许不得转载. 在pte_handle_fa ...

  2. hdu 2112(字典树+最短路)

    HDU Today Time Limit: 15000/5000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total ...

  3. ()java jdbc连接

    测试使用 jdk-8u191-windows-x64.mysql-8.0.12-winx64.mysql-connector-java-8.0.13.jar 查询 import java.sql.*; ...

  4. poj3264(Sparse-Table 算法模板)

    poj3264 题意 询问区间最大值最小值之差. 分析 dp_max[i][j] 表示以 i 为起点,长度为 \(2^j\) 的区间最大值. 利用递推预处理出区间最大值最小值. code #inclu ...

  5. 深入JS正则先行断言

    这里是 Mastering Lookahead and Lookbehind 文章的简单翻译,这篇文章是在自己搜索问题的时候stackoverflow上回答问题的人推荐的,看完觉得写得很不错.这里的简 ...

  6. [POI2014]Solar Panels

    题目大意: $T(T\le1000)$组询问,每次给出$A,B,C,D(A,B,C,D\le10^9)$,求满足$A\le x\le B,C\le y\le D$的最大的$\gcd(x,y)$. 思路 ...

  7. [BZOJ4398]福慧双修/[BZOJ2407]探险

    题目大意: 给定一个$n(n\leq40000)$个点$m(m\leq100000)$条边的有向图,求从$1$出发回到$1$的不经过重复结点的最短路. 思路: 首先Dijkstra求出从1出发到每个结 ...

  8. SQL 增删改查 复习

    首先创建两张表 CREATE TABLE Teacher ( Id ,) NOT NULL PRIMARY KEY, Name ) NOT NULL, ); CREATE TABLE Student ...

  9. CAP理论下对比ACID模型与BASE模型

    CAP介绍 Consistency(一致性), 数据一致更新,所有数据变动都是同步的.比如网购,库存减少的同时资金增多.Availability(可用性), 好的响应性能.比如支付操作10ms内响应用 ...

  10. ANDROID模拟器访问本地WEB应用10.0.2.2

    在一般的Java Web程序开发中,我们通常使用localhost或者127.0.0.1来访问本机的Web服务,但是如果我们在Android模拟器中也采用同样的地址来访问,Android模拟器将无法正 ...