【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. ...
随机推荐
- Map初始化
转载至:http://blog.csdn.net/dujianxiong/article/details/54849079 第一种方法:static块初始化 public class Demo{ pr ...
- Python编程Web框架 :Django 从入门到精通
Django是一个高级别的Python Web框架,它鼓励快速开发和干净实用的设计. 现在我们开始学习它. Django学习之 第一章:Django介绍 Django学习之 第二章:Django快速上 ...
- javascript中构造函数知识总结
构造函数的说明 1.1 构造函数是一个模板 构造函数,是一种函数,主要用来在创建对象时对 对象 进行初始化(即为对象成员变量赋初始值),并且总是与new运算符一起使用. 1.2 new 运算符 new ...
- hadoop基础学习
MR系类: ①hadoop生态 >MapReduce:分布式处理 >Hdfs:hadoop distribut file system >其他相关框架 ->unstructur ...
- 【原创】打印GC log
-verbose:gc -XX:+PrintGCTimeStamps -XX:+PrintGCDetails -Xloggc:c:/gc.log
- (转载) IaaS, PaaS, Saas
如果你是一个网站站长,想要建立一个网站.不采用云服务,你所需要的投入大概是:买服务器,安装服务器软件,编写网站程序. 现在你追随潮流,采用流行的云计算,如果你采用 IaaS 服务,那么意味着你就不用自 ...
- 杭电1003 Max Sum TLE
这一题目是要求连续子序列的最大和,所以在看到题目的一瞬间就想到的是把所有情况列举出来,再两个两个的比较,取最大的(即为更新最大值的意思),这样的思路很简单,但是会超时,时间复杂度为O(n^3),因为有 ...
- Kattis - Different Distances
Input The input file contains up to 10001000 test cases, each of which contains five real numbers, x ...
- 洛谷P3958 奶酪 并查集
两个空洞可互达当且仅当两个空洞相切,即球心距离小于等于球的直径. 一一枚举两个可互达的空洞,并用并查集连起来即可. Code: #include<cstdio> #include<c ...
- WEBGL学习【二】平面图形
<html lang="zh-CN"> <head> <title>NeHe's WebGL</title> <meta ch ...