题目大意:
  日历上博弈,从给定的日期,按照下述规则跳转日期:
    1.跳到第二天;
    2.调到下个月相同的日期(如果没有就不能跳转)。
  刚刚好跳到2001年11月4日的人胜,跳转时不能跳到2001年11月4日以后。
  现在A和B轮流跳,问A是否有必胜策略。

思路:
  如果不考虑边界情况,每一个对应的日期都有两个直接相连的后继状态,也同时是两个日期直接相连的后继状态。
  这样,所有的状态构成一个DAG,我们可以在DAG上进行DP。
  一个状态是必败状态当且仅当它的两个前驱状态都是必胜状态。
  一个状态是必胜状态当且仅当它的其中一个前驱状态是必败状态。
  我们可以先预处理出所有日期所对应的状态,然后回答即可。
  另外本题也有找规律的做法,设月份为m,日期为d。
  则当m+d为偶数时必胜,当m+d为奇数时必败。
  特别地,当m=9或11且d=30时,也为必胜状态。

 #include<map>
#include<cstdio>
#include<cctype>
inline int getint() {
register char ch;
while(!isdigit(ch=getchar()));
register int x=ch^'';
while(isdigit(ch=getchar())) x=(((x<<)+x)<<)+(ch^'');
return x;
}
struct Date {
int y,m,d;
bool operator < (const Date &another) const {
if(y<another.y) {
return true;
} else if(y==another.y){
if(m<another.m) {
return true;
} else if(m==another.m) {
if(d<another.d) return true;
}
}
return false;
}
bool operator <= (const Date &another) const {
if(y<another.y) {
return true;
} else if(y==another.y){
if(m<another.m) {
return true;
} else if(m==another.m) {
if(d<=another.d) return true;
}
}
return false;
}
bool isleap() const {
return (!(y%)&&(y%))||!(y%);
}
int day() const {
if(m==||m==||m==||m==||m==||m==||m==) return ;
if(m==||m==||m==||m==) return ;
return isleap()?:;
}
Date decday() const {
Date ret=*this;
ret.d--;
if(!ret.d) {
ret.m--;
if(!ret.m) {
ret.y--;
ret.m=;
}
ret.d=ret.day();
}
return ret;
}
Date decmonth() const {
Date ret=*this;
ret.m--;
if(!ret.m) {
ret.y--;
ret.m=;
}
if(ret.d>ret.day()) return (Date){,,};
return ret;
}
Date incday() const {
Date ret=*this;
ret.d++;
if(ret.d>ret.day()) {
ret.m++;
if(ret.m==) {
ret.y++;
ret.m=;
}
ret.d=;
}
return ret;
}
Date incmonth() const {
Date ret=*this;
ret.m++;
if(ret.m==) {
ret.y++;
ret.m=;
}
if(ret.d>ret.day()) return (Date){,,};
return ret;
}
};
const Date begin=(Date){,,},end=(Date){,,};
std::map<Date,bool> m;
inline void dp() {
for(Date d=end;begin<=d;d=d.decday()) {
if(d.incday()<=end) {
m[d]|=!m[d.incday()];
}
if(d.incmonth()<=end) {
m[d]|=!m[d.incmonth()];
}
}
}
inline bool query(const int &y,const int &mm,const int &d) {
return m[(Date){y,mm,d}];
}
int main() {
dp();
for(register int n=getint();n;n--) {
const int &y=getint(),&m=getint(),&d=getint();
puts(query(y,m,d)?"YES":"NO");
}
return ;
}

[POJ1082]Calendar Game的更多相关文章

  1. poj1082 Calendar Game (博弈)

    题意是:Adam和Eve两人做游戏,开始给出一个日期,截止日期是2011.11.4,游戏规则如下: 每个人只能将天数增加一天或者将月份增加一天.如果下个月没有这一天,那么只能增加天数. 游戏胜利定义为 ...

  2. 【POJ1082】Calendar Game (博弈)

    [题目] Description Adam and Eve enter this year's ACM International Collegiate Programming Contest. La ...

  3. Java 时间类-Calendar、Date、LocalDate/LocalTime

    1.Date 类 java.util.Date是一个"万能接口",它包含日期.时间,还有毫秒数,如果你只想用java.util.Date存储日期,或者只存储时间,那么,只有你知道哪 ...

  4. Js: Extensible Calendar Examples

    http://ext.ensible.comhttps://github.com/bmoeskau/Extensiblehttps://github.com/TeamupCom/extensibleh ...

  5. Calendar类

    Calendar类 注意:根据日历规则,如果想要这个月减去5天,那么则为: add(Calendar.Day,-5) 成员方法: public int get(int field):返回给定日历段的值 ...

  6. This month Calendar

    package fourth;import java.text.DateFormatSymbols;import java.util.*;public class CalendarTest { pub ...

  7. calendar的一些操作

    一.通过分析日期函数,根据日期进行一系列操作,例如:我们需要知道2个时间段中所有的日期等等. 由于Calendar 类是一个抽象类,因此我们不能通过new来获取该对象的实例.我们可以通过其类方法 ge ...

  8. java-String Date Calendar之间的转换

    1.Calendar 转化 String Calendar calendat = Calendar.getInstance(); SimpleDateFormat sdf = new SimpleDa ...

  9. jQuery Ion.Calendar 日期/日历

    在线实例 实例演示 默认 实例演示 每周第一天 实例演示 输入框插件 实例演示 HTML data 属性 实例演示 回调函数1 实例演示 回调函数2 使用方法 <div id="cal ...

随机推荐

  1. vue表格中显示金额格式化与保存时格式化为数字并校验!

    最近项目中遇到了成本计算的,需要显示金额,保存一下,以后方便直接拿来用! 一 数字转金额格式显示 //数字转金额格式 format:function(s){ if(/[^0-9\.]/.test(s) ...

  2. python的新特性

    http://www.jb51.net/article/67699.htm Python中用format函数格式化字符串的用法:http://www.jb51.net/article/63672.ht ...

  3. ubuntu16.04 eclipse+pydev 配置

    参考:http://blog.csdn.net/bluish_white/article/details/56509446,http://blog.csdn.net/qing101hua/articl ...

  4. 用sklearn计算卡方检验P值

    情形: 1. 对于一批分类变量,我们通常要评价两两之间的相关程度. 2. 因变量是分类变量,衡量其他分类变量和因变量的相关性高低. 来源:https://blog.csdn.net/snowdropt ...

  5. python logging 日志

    logging与print 区别,为什么需要logging? 在写脚本的过程中,为了调试程序,我们往往会写很多print打印输出以便用于验证,验证正确后往往会注释掉,一旦验证的地方比较多,再一一注释比 ...

  6. java基础67 JavaScript通过关系找节点、添加附件(网页知识)

    1.通过关系找节点(父子关系,兄弟关系) 1.1.常用方法 parentNode:获取当前元素的父节点.    childNodes:获取当前元素的所有下一级子元素    firstChild:获取当 ...

  7. 基于RESTful API 设计用户权限控制

    RESTful简述 本文是基于RESTful描述的,需要你对这个有初步的了解. RESTful是什么? Representational State Transfer,简称REST,是Roy Fiel ...

  8. C压缩字符串中的空格

    使用纯C语言,去除一个字符串开头和结尾的空格,内部若有连续空格只保留一个.  C Code  12345678910111213141516171819202122232425262728293031 ...

  9. 汇编看C函数调用

    http://blog.csdn.net/wishfly/article/details/5022008   简单的函数调用,通过简单的函数调用反汇编可以清楚了解如下 1.栈到底是什么,如何操纵栈的? ...

  10. 课堂实验-String类和Arrays类

    课堂实验 在IDEA中以TDD的方式对String类和Arrays类进行学习 测试相关方法的正常,错误和边界情况 String类 charAt split Arrays类 sort binarySea ...