【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. ...
随机推荐
- HBase编程 API入门系列之delete(管理端而言)(9)
大家,若是看过我前期的这篇博客的话,则 HBase编程 API入门之delete(客户端而言) 就知道,在这篇博文里,我是在客户端里删除HBase表的. 这里,我带领大家,学习更高级的,因为,在开发中 ...
- Hadoop MapReduce编程 API入门系列之挖掘气象数据版本2(十)
下面,是版本1. Hadoop MapReduce编程 API入门系列之挖掘气象数据版本1(一) 这篇博文,包括了,实际生产开发非常重要的,单元测试和调试代码.这里不多赘述,直接送上代码. MRUni ...
- Kotlin基础语法:变量、函数、类、枚举、控制流
一切都需要从基础学起! 前言: 在Kotlin语言中,没有分号的概念了,也就是每一行代码,都不在需要用分号结束了 点击查看代码 定义 常量:val --相当于java当中的final 变量:var 关 ...
- 记一个男默女泪的 BUG
姗姗来迟的词频统计代码 BUG 的发现 1. 此前提交的第一次代码作业总结博客 http://www.cnblogs.com/ustczwq/p/8680704.html 2. BUG 本天成,妙手偶 ...
- 如何在Word的方框中打对号
在word中,选择“插入”-“符号”,选择字体为“wingdings”,在倒数第二个特殊字符既是方框中有对号的特殊字符. 1. 2. 3.
- 使用QT创建PythonGUI程序
1. 挑选 GUI设计程序: wxPython Vs. pyQt4 参考链接:http://www.douban.com/group/topic/14590751/ (1):wxWidgets wxP ...
- jemeter安装步骤
1.jmeter下载地址:http://jmeter.apache.org/download_jmeter.cgi 2.在安装jmeter之前首先要安装jdk1.8以上版本,朋友们,千万不要忘了 jd ...
- C++基础 (4) 第四天 this指针 全局函数和成员函数 友元 操作符重载
1static强化练习-仓库进货和出货 #define _CRT_SECURE_NO_WARNINGS #include <iostream> using namespace std; c ...
- 代码检查工具sonarqube介绍及使用
亲测有效 环境:springboot+gradle+jdk1.8+sonarqube7.4 一.说明: SonarQube为静态代码检查工具,采用B/S架构,帮助检查代码缺陷,改善代码质量,提高开发速 ...
- vue组件通信,点击传值,动态传值(父传子,子传父)
转载:https://blog.csdn.net/xr510002594/article/details/83304141 一.父组件传子组件,核心--props 在这里触发 handleClick ...