【POJ 1082】 Calendar Game
【题目链接】
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的更多相关文章
- bzoj 2295: 【POJ Challenge】我爱你啊
2295: [POJ Challenge]我爱你啊 Time Limit: 1 Sec Memory Limit: 128 MB Description ftiasch是个十分受女生欢迎的同学,所以 ...
- 【链表】BZOJ 2288: 【POJ Challenge】生日礼物
2288: [POJ Challenge]生日礼物 Time Limit: 10 Sec Memory Limit: 128 MBSubmit: 382 Solved: 111[Submit][S ...
- BZOJ2288: 【POJ Challenge】生日礼物
2288: [POJ Challenge]生日礼物 Time Limit: 10 Sec Memory Limit: 128 MBSubmit: 284 Solved: 82[Submit][St ...
- BZOJ2293: 【POJ Challenge】吉他英雄
2293: [POJ Challenge]吉他英雄 Time Limit: 1 Sec Memory Limit: 128 MBSubmit: 80 Solved: 59[Submit][Stat ...
- BZOJ2287: 【POJ Challenge】消失之物
2287: [POJ Challenge]消失之物 Time Limit: 10 Sec Memory Limit: 128 MBSubmit: 254 Solved: 140[Submit][S ...
- BZOJ2295: 【POJ Challenge】我爱你啊
2295: [POJ Challenge]我爱你啊 Time Limit: 1 Sec Memory Limit: 128 MBSubmit: 126 Solved: 90[Submit][Sta ...
- BZOJ2296: 【POJ Challenge】随机种子
2296: [POJ Challenge]随机种子 Time Limit: 1 Sec Memory Limit: 128 MBSec Special JudgeSubmit: 114 Solv ...
- BZOJ2292: 【POJ Challenge 】永远挑战
2292: [POJ Challenge ]永远挑战 Time Limit: 10 Sec Memory Limit: 128 MBSubmit: 513 Solved: 201[Submit][ ...
- 【POJ 1125】Stockbroker Grapevine
id=1125">[POJ 1125]Stockbroker Grapevine 最短路 只是这题数据非常水. . 主要想大牛们试试南阳OJ同题 链接例如以下: http://acm. ...
随机推荐
- (转载) 小议TCP的MSS(最大分段)以及MTU(最大传输单元)
[背景知识] MTU: Maximum Transmission Unit 最大传输单元 MSS: Maximum Segment Size 最大分段大小PPPoE: PPP Over Ethern ...
- Windows环境下使用强大的wget工具
安装 下载[http://www.interlog.com/~tcharron/wgetwin.html] 解压到目录 比如我解压到D:\Tool\wget 添加wget环境变量,这样使用就更方便了, ...
- lz的第一个RN项目
这是lz 成功在原有项目上集成的第一个ReactNative 项目. 参考官方网址: http://reactnative.cn/docs/0.43/integration-with-existing ...
- Redis入门笔记-redis内部数据结构(01)
redis是一个轻量级的Nodsql数据库,使用kev-value的形式存储数据,在redis的世界里,没有整数.浮点数等概念,大多数情况下数据以字符串形式展现,偶尔会出现Long类型数据的场景. 一 ...
- python tips:文件读取——换行符的问题
问题:在windows系统中,换行的符号是'\r\n'.python在读文件的时候为了系统兼容,会默认把'\r','n','\r\n'都视作换行.但是在windows文件中,可能在同一行中同时存在'\ ...
- gitlab安装和汉化
Centos 7.x 安装 gitlab-ce-8.8.0-ce 一.安装配置依赖项 yum -y install curl unzip policycoreutils git wget # 依赖包 ...
- 如何检查Windows网络通信端口占用
最近本地测试jsp程序发现tomcat启动失败,无法监听8080端口,也没记得别的什么程序占用了8080端口,干脆就改成了8090端口先用着.今天找了找Windows上查看网络通信端口占用的方法. 先 ...
- Project Euler 25 1000-digit Fibonacci number
题意:在斐波那契数列( 1 ,1,2,3,5 ...... )中,第一个有1000位数字的是第几项? 思路:滚动数组 + 大数加法 /********************************* ...
- liunx 里面安装phpstudy环境s
ngixwget -c http://lamp.phpstudy.net/phpstudy.bin chmod +x phpstudy.bin #权限设置 ./phpstudy.bin #运行 ...
- ZooKeeper概念
这可能是把ZooKeeper概念讲的最清楚的一篇文章 相信大家对 ZooKeeper 应该不算陌生,但是你真的了解 ZooKeeper 是什么吗?如果别人/面试官让你讲讲 ZooKeeper 是什么, ...