【题目链接】

http://poj.org/problem?id=1082

【算法】

对于每种状态,要么必胜,要么必败

记忆化搜索即可

【代码】

#include <algorithm>
#include <bitset>
#include <cctype>
#include <cerrno>
#include <clocale>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <limits>
#include <list>
#include <map>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <utility>
#include <vector>
#include <cwchar>
#include <cwctype>
#include <stack>
#include <limits.h> using namespace std; int newy,newm,newd,y,m,d,T;
int f[][][];
int day[] = {,,,,,,,,,,,,}; template <typename T> inline void read(T &x) {
int f = ; x = ; char c = getchar();
for (; !isdigit(c); c = getchar()) { if (c == '-') f = -; }
for (; isdigit(c); c = getchar()) x = x * + c - '';
x *= f;
} bool is_leap(int yy) {
if (((yy % == ) && (yy % != )) || (yy % == ))
return true;
else return false;
} bool check(int yy,int mm,int dd) {
if (is_leap(yy)) day[] = ;
else day[] = ;
if (dd > day[mm]) return false;
if (yy > ) return false;
if ((yy == ) && (mm > )) return false;
if ((yy == ) && (mm == ) && (dd > )) return false;
return true;
} void next_day() {
if (is_leap(newy)) day[] = ;
else day[] = ;
newd++;
if (newd > day[newm]) { newd = ; newm++; }
if (newm > ) { newm = ; newy++; }
} void next_month() {
newm++;
if (newm > ) { newm = ; newy++; }
} bool dfs(int yy,int mm,int dd) {
if (f[yy][mm][dd] != -)
return f[yy][mm][dd];
f[yy][mm][dd] = ;
newy = yy; newm = mm; newd = dd;
next_day();
if (check(newy,newm,newd)) {
f[yy][mm][dd] |= (!dfs(newy,newm,newd));
if (f[yy][mm][dd] == )
return true;
}
newy = yy; newm = mm; newd = dd;
next_month();
if (check(newy,newm,newd))
f[yy][mm][dd] |= (!dfs(newy,newm,newd));
return f[yy][mm][dd];
} int main() { memset(f,,sizeof(f));
f[][][] = ;
read(T); while (T--) {
read(y); read(m); read(d);
puts((dfs(y,m,d))?("YES"):("NO"));
} return ; }

【POJ 1082】 Calendar Game的更多相关文章

  1. bzoj 2295: 【POJ Challenge】我爱你啊

    2295: [POJ Challenge]我爱你啊 Time Limit: 1 Sec  Memory Limit: 128 MB Description ftiasch是个十分受女生欢迎的同学,所以 ...

  2. 【链表】BZOJ 2288: 【POJ Challenge】生日礼物

    2288: [POJ Challenge]生日礼物 Time Limit: 10 Sec  Memory Limit: 128 MBSubmit: 382  Solved: 111[Submit][S ...

  3. BZOJ2288: 【POJ Challenge】生日礼物

    2288: [POJ Challenge]生日礼物 Time Limit: 10 Sec  Memory Limit: 128 MBSubmit: 284  Solved: 82[Submit][St ...

  4. BZOJ2293: 【POJ Challenge】吉他英雄

    2293: [POJ Challenge]吉他英雄 Time Limit: 1 Sec  Memory Limit: 128 MBSubmit: 80  Solved: 59[Submit][Stat ...

  5. BZOJ2287: 【POJ Challenge】消失之物

    2287: [POJ Challenge]消失之物 Time Limit: 10 Sec  Memory Limit: 128 MBSubmit: 254  Solved: 140[Submit][S ...

  6. BZOJ2295: 【POJ Challenge】我爱你啊

    2295: [POJ Challenge]我爱你啊 Time Limit: 1 Sec  Memory Limit: 128 MBSubmit: 126  Solved: 90[Submit][Sta ...

  7. BZOJ2296: 【POJ Challenge】随机种子

    2296: [POJ Challenge]随机种子 Time Limit: 1 Sec  Memory Limit: 128 MBSec  Special JudgeSubmit: 114  Solv ...

  8. BZOJ2292: 【POJ Challenge 】永远挑战

    2292: [POJ Challenge ]永远挑战 Time Limit: 10 Sec  Memory Limit: 128 MBSubmit: 513  Solved: 201[Submit][ ...

  9. 【POJ 1125】Stockbroker Grapevine

    id=1125">[POJ 1125]Stockbroker Grapevine 最短路 只是这题数据非常水. . 主要想大牛们试试南阳OJ同题 链接例如以下: http://acm. ...

随机推荐

  1. iterator和iterable的区别

    相关博客:  http://blog.csdn.net/lipengcn/article/details/51700153         Java中Iterable和Iterator的辨析 http ...

  2. 深入分析setContentView

    在网络层,互联网提供所有应用程序都要使用的两种类型的服务,尽管目前理解这些服务的细节并不重要,但在所有TCP/IP概述中,都不能忽略他们: 无连接分组交付服务(Connectionless Packe ...

  3. H5 微信公众号 监听返回事件

    /*-----监听返回事件-----*/ function pushHistory(returnUrl,currentUrl,currentTitle) { window.addEventListen ...

  4. python爬虫:爬取凤凰指数

    在知乎上看到的这个问题,讲讲我爬取过程中遇到的问题: 1.循环爬取其他页面,在其他项目中用循环一般可以搞定,可是这个,第一页和第二第三页的表格是不同的,所以要重新写规则,我懒,写了第一页后,就不想在写 ...

  5. dll文件:关于MFC程序不能定位输入点

    问题:无法定位程序输入点到动态链接库上...... 过程:找完整个工程文件夹: APS为资源文件: resource.h为定义文件: 完全复制 除主文件以外的所有文件,程序可用: 在主程序框Cpp文件 ...

  6. 项目随笔之springmvc中freemark如何获取项目路径

    转载:http://blog.csdn.net/whatlookingfor/article/details/51538995 在SpringMVC框架中使用Freemarker试图时,要获取根路径的 ...

  7. gulp给文件后添加md5时间戳

    这里为总的方法,实际项目中拷贝出来的,底下有详细的总结以及只针对添加时间戳的方法 1 // 引入 gulp及组件 var gulp = require('gulp'), autoprefixer = ...

  8. Laravel 查询某天数据 whereDate

  9. MongoDB_pymongo

    python使用pymongo访问MongoDB的基本操作 安装pymongo: pip install pymongo from pymongo import MongoClient import ...

  10. Python中用绘图库绘制一条蟒蛇

    一..构思设计蟒蛇的长度颜色等 首先,我们来构思一个简单的蟒蛇.让它的颜色为黄色,形状为一条正在爬行的蟒蛇. 二..准备绘图库 Python中有一个绘图库叫turtle我们先引入它. import t ...