hdu 1079 Calendar Game sg函数 难度:0
Calendar Game
Time Limit: 5000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 2766 Accepted Submission(s): 1594
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.
2001 11 3
2001 11 2
2001 10 3
NO
NO
思路:sg打表,为了不爆栈从高往低打表,注意日期转换
经验教训:代码风格太凌乱了导致没发现bug
#include <cstdio>
#include <cstring>
using namespace std;
int dayofmonth[12]={31,28,31,30,31,30,31,31,30,31,30,31};
int sg[45000];//记录结果
bool isgapyear(int year){//是否间隔年
if(year%4==0&&(year%100!=0||year%400==0))return true;
return false;
}
int getdofm(int year,int month){//得到这个月天数
int ans=dayofmonth[month];
if(month==1&&isgapyear(year))ans++;
return ans;
}
int getdate(int year,int month,int day){//得到从1970.1.1开始的天数
int date=0;
for(int i=1900;i<year;i++)date+=(isgapyear(i)?366:365);
for(int i=0;i<month;i++){
date+=getdofm(year,i);
}
date+=day;
return date;
}
void getcalendar(int date ,int& year,int &month,int &day){//由从1970开始的天数得到年月日
int accu=0;
for(int i=0;i<102;i++){
accu+=(isgapyear(i+1900)?366:365);
if(date<accu){
year=i;date-=accu-(isgapyear(i+1900)?366:365);break;
}
else if(date==accu){
year=i;day=31;month=11;return ;
}
}
accu=0;
for(int i=0;i<12;i++){
int dm=getdofm(year+1900,i);
accu+=dm;
if(accu>date){
month=i;
date-=accu-dm;
break;
}
else if(accu==date){
month=i;
date=dm;
break;
}
}
day=date;
}
int seg(int date){//sg函数
if(sg[date]!=-1)return sg[date];
int year,month,day;
getcalendar(date,year,month,day);
if(seg(date+1)==0)return sg[date]=1;//日历左移
int ty,tm,td;getcalendar(date+getdofm(year+1900,month),ty,tm,td);
if((day==td&&date+getdofm(year+1900,month)<=37198)&&seg(date+getdofm(year+1900,month))==0)return sg[date]=1;//如果日历下一个月存在这一天,试着移一个月
return sg[date]=0;
}
int main(){
memset(sg,-1,sizeof(sg));
sg[37198]=0;
for(int i=37197 ;i>0;i--){
seg(i);
}
int y,m,d;
int T;
scanf("%d",&T);
while(T--){
scanf("%d%d%d",&y,&m,&d);m--;
int date=getdate(y,m,d);
printf("%s\n",seg(date)==0?"NO":"YES");
}
return 0;
}
hdu 1079 Calendar Game sg函数 难度:0的更多相关文章
- hdu 1536&&1944 S-Nim sg函数 难度:0
S-Nim Time Limit: 5000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submi ...
- hdu 3032 Nim or not Nim? sg函数 难度:0
Nim or not Nim? Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)T ...
- hdu 3032(博弈sg函数)
题意:与原来基本的尼姆博弈不同的是,可以将一堆石子分成两堆石子也算一步操作,其它的都是一样的. 分析:由于石子的堆数和每一堆石子的数量都很大,所以肯定不能用搜索去求sg函数,现在我们只能通过找规律的办 ...
- HDU 5724 Chess(SG函数+状态压缩)
http://acm.split.hdu.edu.cn/showproblem.php?pid=5724 题意: 现在有一个n*20的棋盘,上面有一些棋子,双方每次可以选择一个棋子把它移动到其右边第一 ...
- HDU 1079 Calendar Game (博弈或暴搜)
题意:给定一个日期,然后 A 和 B 双方进行操作,谁先把日期变成2001年11月04日,将获胜,如果超过该日期,则输了,就两种操作. 第一种:变成下一天,比如现在是2001.11.3 变成 2001 ...
- HDU 5724 Chess(SG函数)
Chess Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Total Submi ...
- HDU 1535 S-Nim(SG函数)
S-Nim Time Limit: 5000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submi ...
- HDU 1079 Calendar Game (博弈论-sg)
版权声明:欢迎关注我的博客,本文为博主[炒饭君]原创文章.未经博主同意不得转载 https://blog.csdn.net/a1061747415/article/details/32336485 C ...
- hdu 1517 A Multiplication Game 段sg 博弈 难度:0
A Multiplication Game Time Limit: 5000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Ot ...
随机推荐
- 『NiFi 自定义 Processor 无法获取到 Logger』问题解决
一.概述 自定义的 Processor 继承了 AbstractProcessor,而 AbstractProcessor 继承了 AbstractSessionFactoryProcessor ,g ...
- Python 实例2—购物车
老男孩教学学习笔记 """启动程序后,让用户输入工资,然后打印商品列表允许用户根据商品编号购买商品用户选择商品后,检测余额是否够,够就直接扣款,不够就提醒可随机退出,退出 ...
- selenium实现excel文件数据的读、写
在进行软件测试或设计自动化测试框架时,一个不可避免的过程就是: 参数 化,在利用 python 进行自动化测试开发时,通常会使用 excel 来做数据管 理,利用 xlrd.xlwt 开源包来读写 e ...
- hive union all使用注意
UNION用于联合多个select语句的结果集,合并为一个独立的结果集,结果集去重. UNION ALL也是用于联合多个select语句的结果集.但是不能消除重复行.现在hive只支持UNION AL ...
- [转]将Eclipse设置为黑色主题 方式一
将Eclipse设置为黑色主题 觉得黑色的主题&配色很高大上,于是花了点时间实践出下面一种方法. 修改代码编辑区配色 修改整个软件主题 先上成果图: 但是进度条依旧是白色的,不知道怎么弄了╮( ...
- Docker---大型项目容器化改造
虚拟化和容器化是项目云化不可避免的两个问题.虚拟化由于是纯平台操作,一个运行于linux操作系统的项目几乎不需要做任何改造就可以支持虚拟化.而项目如果要支持容器化则需要做许多细致的改造工 ...
- hadoop cgroup+container配置
配置container-executor.cfg vim etc/hadoop/container-executor.cfg yarn.nodemanager.linux-container-exec ...
- servlet类与Spring Controller类的关系
以前的java web项目,需要在web.xml中定义servlet,对应不同的请求,而在spring项目中,我们用controller定义了各种各样的servlet(当然不包括DispatcherS ...
- shell进阶教程
背景:就自己常用的shell脚本写作风格,总结了一些知识点.也是作为交接工作的一部分文档.部分内容单独写 #!/bin/sh # shell脚本进阶教程 # 1.常用知识点:变量设置/日期设置/格式化 ...
- java问卷调查
你对自己的未来有什么规划?做了哪些准备? 我对自己今后五年有一定的规划,那就是多学一些信息技术上的知识,当今的社会高度信息化,且在以后也有高速发展的势头,所以我认为只有学习足够的专业知识,才可以适应未 ...