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> ...
随机推荐
- C#模拟进行压力测试
using System; using System.Diagnostics; using System.IO; using System.Net; using System.Text; using ...
- 【原创】DQS安装失败——系统重新引导是否处于挂起状态
问题: 安装完SQL Server 2012后,准备安装DQS服务,但是总是提示:操作“检查系统重新引导是否处于挂起状态”已完成,但有错误,正在中止安装.非常无奈,因为都根据其要求重启 ...
- VS2008中的配置文件app.config简单小结
应用程序的配置文件用于读取和保存简单的本地数据,vs中新增配置文件可以直接在项目的”属性“-”设置“里添加,添加后在项目的Properties文件夹会多出一组两个文件:Settings.setting ...
- MVC5 WebAPI 跨域处理
问题描述: 在使用ASP.NET的MVC5进行WebAPI开发的时候,在跨域的情况下会报跨域的错, No 'Access-Control-Allow-Origin' header is present ...
- 关于asp.net中gridview的问题,关于footer,16aspx上下的英语交流网程序,管理员的添加和修改有问题
css部分 这是添加用户的方法 但是A.AdminName 和后面的A.取到的都是空值protected void GridView1_RowCommand(object sender,GridVie ...
- Netty源码学习(四)Netty服务器是如何启动的?
本文会分析Netty服务器的启动过程,采用的范例代码是Netty编写的Echo Server. 0. 声明acceptor与worker 由于Netty采用的reactor模型,所以需要声明两组线程, ...
- elasticsearch配置文件(elasticsearch.yml)详解
来自:http://www.searchtech.pro/articles/2013/02/18/1361194291548.html elasticsearch的config文件夹里面有两个配置文 ...
- 项目管理软件Readmine安装配置
1.安装依赖 #yum install curl-devel sqlite-devel libyaml-devel -y 2.安装rvm #curl -L https://get.rvm.io | b ...
- Python的功能模块[1] -> struct -> struct 在网络编程中的使用
struct模块 / struct Module 在网络编程中,利用 socket 进行通信时,常常会用到 struct 模块,在网络通信中,大多数传递的数据以二进制流(binary data)存在. ...
- La 4976 Defense lines
蓝书紫书上都有的一道题...这里就懒得说题解了. 但是我竟然WA了6次!为什么呢??? 一开始没看见连续子序列..... 后来插入的时候忘判断了是不是比前驱大.... 所以我们只需要维护一个权值递增( ...