poj 1079 Calendar Game(博弈论 SG)
Calendar Game
Time Limit: 5000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 2519 Accepted Submission(s): 1438
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.
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.
3
2001 11 3
2001 11 2
2001 10 3
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)的更多相关文章
- POJ 2960 S-Nim 博弈论 sg函数
http://poj.org/problem?id=2960 sg函数几乎是模板题. 调试代码的最大障碍仍然是手残在循环里打错变量名,是时候换个hydra产的机械臂了[超想要.jpg] #includ ...
- HDU 1847 Good Luck in CET-4 Everybody! (博弈论sg)
Good Luck in CET-4 Everybody! Problem Description 大学英语四级考试就要来临了,你是不是在紧张的复习?或许紧张得连短学期的ACM都没工夫练习了.反正我知 ...
- HDU.1847 Good Luck in CET-4 Everybody! ( 博弈论 SG分析)
HDU.1847 Good Luck in CET-4 Everybody! ( 博弈论 SG分析) 题意分析 简单的SG分析 题意分析 简单的nim 博弈 博弈论快速入门 代码总览 //#inclu ...
- 【bzoj3576】[Hnoi2014]江南乐 博弈论+SG定理+数学
题目描述 两人进行 $T$ 轮游戏,给定参数 $F$ ,每轮给出 $N$ 堆石子,先手和后手轮流选择石子数大于等于 $F$ 的一堆,将其分成任意(大于1)堆,使得这些堆中石子数最多的和最少的相差不超过 ...
- HDU 1079 Calendar Game (博弈论-sg)
版权声明:欢迎关注我的博客,本文为博主[炒饭君]原创文章.未经博主同意不得转载 https://blog.csdn.net/a1061747415/article/details/32336485 C ...
- hdu 1079 Calendar Game sg函数 难度:0
Calendar Game Time Limit: 5000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Tot ...
- POJ 2425 A Chess Game 博弈论 sg函数
http://poj.org/problem?id=2425 典型的sg函数,建图搜sg函数预处理之后直接求每次游戏的异或和.仍然是因为看不懂题目卡了好久. 这道题大概有两个坑, 1.是搜索的时候vi ...
- (博弈论)hdoj 1079 Calendar Game
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1079 题解:题目大意,两个人Adam和Eve一块儿玩游戏,游戏规则是从1900年1月1日到2001年1 ...
- poj 3710 Christmas Game【博弈论+SG】
也就是转换到树形删边游戏,详见 https://wenku.baidu.com/view/25540742a8956bec0975e3a8.html #include<iostream> ...
随机推荐
- 简述web工程师的职责与学习
最近两年web突然很火,也有很多人涌入这一行,但这行实际上是进来的人很多,出去的人也很多. 在我眼里,Web前端开发工程师的职责有:1.Web前端表现层及与前后端交互的架构设计和开发2.配合后台开发人 ...
- Sublime Text 3 使用技巧,插件
一.安装 官网下载最新版安装包,地址自行百度,或者我的网盘 不要安装某些网站提供的安装包*3,原因如下: 1,安装过程捆绑一些不必要的软件 2,测试过程中,某些功能受到限制 快捷键大全 3,一些设置, ...
- net页面生命周期
ASP.NET 页运行时,此页将经历一个生命周期,在生命周期中将执行一系列处理步骤.这些步骤包括初始化.实例化控件.还原和维护状态.运行事件处理程序代码以及进行呈现.了解页的生命周期非常重要,这样就能 ...
- HDU 4920.Matrix multiplication-矩阵乘法
Matrix multiplication Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/ ...
- 几何【P2313】 [HNOI2005]汤姆的游戏
顾z 你没有发现两个字里的blog都不一样嘛 qwq 题目描述--->p2313 [HNOI]汤姆的游戏 分析 说不上是分析. 数据范围给出来,这题明显暴力啊emmm. 个人认为的坑点. 这题不 ...
- Unique Word Abbreviation -- LeetCode
An abbreviation of a word follows the form <first letter><number><last letter>. Be ...
- First Missing Positive -- LeetCode
Given an unsorted integer array, find the first missing positive integer. For example,Given [1,2,0] ...
- JAVA和.NET工作流相关项目收集
.NET以自主实现为主, 暂未发现使用WWF框架开发的开源工作流, java以BPM系为主 . .NET: RoadFlow : http://www.cqroad.cn/ 使用了百度编辑器扩展 ...
- 手动删除SVCH0ST.EXE的方法
最近几天在办公室的计算机上又发现了一种病毒,在进程管理器中多出了两个进程:SVCH0ST.EXE.IEXPLORE.EXE,经一番查看揭开了它们的真面目,现将清除这种病毒的方法总结如下: 病毒 ...
- nginx -- 启动, 重启, 关闭
Nginx的启动.停止与重启 重启: nginx -s reload 启动 启动代码格式:nginx安装目录地址 -c nginx配置文件地址 例如: [root@LinuxServer sbin] ...