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. Linux C/C++内存泄漏检测工具:Valgrind

    Valgrind 是一款 Linux下(支持 x86.x86_64和ppc32)程序的内存调试工具,它可以对编译后的二进制程序进行内存使用监测(C语言中的malloc和free,以及C++中的new和 ...

  2. LVM更换硬盘

    #检测坏道 smartctl -a /dev/sdd #硬盘检测 e2fsck -f /dev/mapper/vg_root-lv_data #重新定义空间大小,将原来的大小上减去要移走的硬盘 res ...

  3. 【linux高级程序设计】(第十二章)Linux多线程编程 4

    读写锁 书上有读者写者的代码,我实在是懒得实现一遍了.跟之前的代码差不多. 多线程异步信号处理 int pthread_kill (pthread_t __threadid, int __signo) ...

  4. [BZOJ1051][HAOI2006] 受欢迎的牛 tarjan求联通分量

    1051: [HAOI2006]受欢迎的牛 Time Limit: 10 Sec  Memory Limit: 162 MBSubmit: 5687  Solved: 3016[Submit][Sta ...

  5. 30 分钟学会 Flex 布局

    30 分钟学会 Flex 布局 有酒   617 人赞同了该文章 为什么我要写这一篇关于 Flex 布局的教程? 因为它十分简单灵活,区区简单几行代码就可以实现各种页面的的布局,以前我在学习页面布局的 ...

  6. UVA 624 CD【01背包+路径记录】

    You have a long drive by car ahead. You have a tape recorder, but unfortunately your best music is o ...

  7. redis --- lua 脚本实现原子操作

    如题, 楼主的想法很简单, lua 脚本本身支持原子性, 所以把命令写进一个脚本就行, 当然后续还会优化才能放到生产上,例如缓存脚本 ,redis 本身会缓存执行过的脚本 ,这样速度更快, 再优化, ...

  8. 编译qt提示找不到gmake

    转:http://wuyuans.com/2012/11/gmake-not-found/ 在用debian编译qt4.5的时候提示gmake: not found,gmake是什么东西,用aptit ...

  9. 利用DFS求联通块个数

    /*572 - Oil Deposits ---DFS求联通块个数:从每个@出发遍历它周围的@.每次访问一个格子就给它一个联通编号,在访问之前,先检查他是否 ---已有编号,从而避免了一个格子重复访问 ...

  10. virtualenv 和apache 搭建django时注意事项

    在对应网站的xxx.conf中 WSGIDaemonProcess http://127.0.0.1:80 python-path=/home/user/my_blog_2:/home/user/ve ...