题意:两个人玩游戏,给定一个日期,他们轮流选择日期,可以选择当前日期的下一天,如果下一个月也有这一天的话则也可以选择下一个月的这一天。超过某一日期的人输。

思路:以天为状态,则一共有300多万个左右的状态,然后用dp预处理每个状态是必胜态还是必败态。一个状态是必胜态当且仅存在它的一个后继是必败态,一个状态是必败态当且仅当它的所有后继都是必胜态,写成逻辑式则是:state(now)= !state(next1) || !state(next2) || .. || !state(nextn)

由于空间不足,采用一个4位int存年月日,方法是用8个十进制位,高4位存年,中2位存月,低2位存日。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
/* ******************************************************************************** */
#include <iostream>                                                                 //
#include <cstdio>                                                                   //
#include <cmath>                                                                    //
#include <cstdlib>                                                                  //
#include <cstring>                                                                  //
#include <vector>                                                                   //
#include <ctime>                                                                    //
#include <deque>                                                                    //
#include <queue>                                                                    //
#include <algorithm>                                                                //
#include <map>                                                                      //
#include <cmath>                                                                    //
using namespace std;                                                                //
                                                                                    //
#define pb push_back                                                                //
#define mp make_pair                                                                //
#define X first                                                                     //
#define Y second                                                                    //
#define all(a) (a).begin(), (a).end()                                               //
#define fillchar(a, x) memset(a, x, sizeof(a))                                      //
                                                                                    //
typedef pair<intint> pii;                                                         //
typedef long long ll;                                                               //
typedef unsigned long long ull;                                                     //
                                                                                    //
#ifndef ONLINE_JUDGE                                                                //
void RI(vector<int>&a,int n){a.resize(n);for(int i=0;i<n;i++)scanf("%d",&a[i]);}    //
void RI(){}void RI(int&X){scanf("%d",&X);}template<typename...R>                    //
void RI(int&f,R&...r){RI(f);RI(r...);}void RI(int*p,int*q){int d=p<q?1:-1;          //
while(p!=q){scanf("%d",p);p+=d;}}void print(){cout<<endl;}template<typename T>      //
void print(const T t){cout<<t<<endl;}template<typename F,typename...R>              //
void print(const F f,const R...r){cout<<f<<", ";print(r...);}template<typename T>   //
void print(T*p, T*q){int d=p<q?1:-1;while(p!=q){cout<<*p<<", ";p+=d;}cout<<endl;}   //
#endif // ONLINE_JUDGE                                                              //
template<typename T>bool umax(T&a, const T&b){return b<=a?false:(a=b,true);}        //
template<typename T>bool umin(T&a, const T&b){return b>=a?false:(a=b,true);}        //
template<typename T>                                                                //
void V2A(T a[],const vector<T>&b){for(int i=0;i<b.size();i++)a[i]=b[i];}            //
template<typename T>                                                                //
void A2V(vector<T>&a,const T b[]){for(int i=0;i<a.size();i++)a[i]=b[i];}            //
                                                                                    //
const double PI = acos(-1.0);                                                       //
const int INF = 1e9 + 7;                                                            //
                                                                                    //
/* -------------------------------------------------------------------------------- */
 
const int month[] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
const int maxn = 4e6;
 
struct Node {
    int s;
    int gety() { return s / 10000; }
    int getm() { return s / 100 % 100; }
    int getd() { return s % 100; }
    Node(int y = 0, int m = 0, int d = 0) {
        s = y * 10000 + m * 100 + d;
    }
    Node nextm() {
        int y = gety(), m = getm() + 1, d = getd();
        if (m == 12) {
            y ++;
            m = 0;
        }
        return Node(y, m, d);
    }
};
Node state[maxn];
int cnt;
int hsh[102][12][31];
bool dp[maxn];
 
 
bool leap(int y) {
    return y % 4 == 0 && y % 100 != 0 || y % 400 == 0;
}
 
void pre_init() {
    for (int i = 0; i < 102; i ++) {
        for (int j = 0; j < 12; j ++) {
            int M = month[j];
            if (leap(i + 1900) && j == 1) M ++;
            for (int k = 0; k < M; k ++) {
                state[cnt] = Node(i, j, k);
                hsh[i][j][k] = cnt ++;
            }
        }
    }
    for (int i = hsh[101][10][3] + 1; i < cnt; i ++) dp[i] = true;
    for (int i = hsh[101][10][3] - 1; i >= 0; i --) {
        Node S = state[i].nextm();
        int y = S.gety(), m = S.getm(), d = S.getd();
        dp[i] = !dp[i + 1];
        if (hsh[y][m][d]) dp[i] = dp[i] || !dp[hsh[y][m][d]];
    }
}
int main() {
#ifndef ONLINE_JUDGE
    freopen("in.txt""r", stdin);
    //freopen("out.txt", "w", stdout);
#endif // ONLINE_JUDGE
    pre_init();
    int T;
    cin >> T;
    while (T --) {
        int y, m, d;
        scanf("%d%d%d", &y, &m, &d);
        int n = hsh[y - 1900][m - 1][d - 1];
        puts(dp[n]? "YES" "NO");
    }
    return 0;
}
/* ******************************************************************************** */

[hdu1079]简单博弈的更多相关文章

  1. ACM: NBUT 1107 盒子游戏 - 简单博弈

     NBUT 1107  盒子游戏 Time Limit:1000MS     Memory Limit:65535KB     64bit IO Format:  Practice  Appoint ...

  2. HDU 1564 简单博弈 水

    n*n棋盘,初始左上角有一个石头,每次放只能在相邻的四个位置之一,不能操作者输. 如果以初始石头编号为1作为后手,那么对于每次先手胜的情况其最后一步的四周的编号必定是奇数,且此时编号为偶数,而对于一个 ...

  3. HDU 1079 Calendar Game(简单博弈)

    Calendar Game Time Limit: 5000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Tot ...

  4. hdu 1846 Brave Game 简单博弈

    Problem Description 十年前读大学的时候,中国每年都要从国外引进一些电影大片,其中有一部电影就叫<勇敢者的游戏>(英文名称:Zathura),一直到现在,我依然对于电影中 ...

  5. HDU 4642 Fliping game (2013多校4 1011 简单博弈)

    Fliping game Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Tota ...

  6. [POJ1082&POJ2348&POJ1067&POJ2505&POJ1960]简单博弈题总结

    鉴于时间紧张...虽然知道博弈是个大课题但是花一个上午时间已经极限了... 希望省选过后再回过头来好好总结一遍吧. 接下来为了看着顺眼一点...还是按照难度顺序吧   POJ1082 一道最简单的博弈 ...

  7. acm之简单博弈 Nim Bash Wythoff

    前些日子我打算开了博弈基础,事后想进行总结下 一句话就是分析必胜或必败,异或为0. 以下内容来自转载: Nim游戏的概述: 还记得这个游戏吗?给出n列珍珠,两人轮流取珍珠,每次在某一列中取至少1颗珍珠 ...

  8. BZOJ 1034 泡泡堂BNB 贪心+简单博弈

    同样是今天做bzoj时做到的,感觉能力范围之内的就做了,也是蛮简单的 1034: [ZJOI2008]泡泡堂BNB Time Limit: 10 Sec Memory Limit: 162 MB Su ...

  9. ZOJ 1893 A Multiplication Game 【简单博弈】

    感觉ZJU上有不少博弈的题目. 这道题目还是比较好理解的,题目大概意思是:两人轮流乘一个2-9的数,从1开始乘,求谁的乘积先大于N. 还是寻找必败点必胜点,不过在这个题目里转换成了寻找必败区间必胜区间 ...

随机推荐

  1. 记录在腾讯云上搭建Ubuntu服务器

    为了能让更多的比赛题复现,只好自己去手动搭建服务器 各种奇葩的操作以及很多的由于升级之后出现的问题变成了一个个坑. 写下这篇博客以此来记录我踩过的坑. 第一步 购买一个服务器,当然我购买的是学生版本的 ...

  2. Python 中取代 Printf 大法的工具

    「printf 大法」大概是最早期学到的 debug 方式?不同语言有不同的指令,在 Python 里对应的是 print指令 (加上%或是.format). 刚刚看到「 cool-RR/pysnoo ...

  3. js输入框练习

    这个就是一个输入框的小练习(也是第一次写这个东西) <!DOCTYPE html> <html lang="en"> <head> <me ...

  4. Spring Cloud 系列之 Sleuth 链路追踪(二)

    本篇文章为系列文章,未读第一集的同学请猛戳这里:Spring Cloud 系列之 Sleuth 链路追踪(一) 本篇文章讲解 Sleuth 基于 Zipkin 存储链路追踪数据至 MySQL,Elas ...

  5. Flutter 分页功能表格控件

    老孟导读:前2天有读者问到是否有带分页功能的表格控件,今天分页功能的表格控件详细解析来来. PaginatedDataTable PaginatedDataTable是一个带分页功能的DataTabl ...

  6. window servet 2012 r2 配置php服务器环境

    绑定:https://jingyan.baidu.com/article/0bc808fc2c6a851bd485b92a.html 配置环境:http://www.jb51.net/article/ ...

  7. 详解 Discuz 的 PHP经典加密解密函数 authcode

    函数注释: // $string: 明文 或 密文 // $operation:DECODE表示解密,其它表示加密 // $key: 密匙 // $expiry:密文有效期 function auth ...

  8. redis的5种数据类型

    卸载服务:redis-server --service-uninstall 开启服务:redis-server --service-start 停止服务:redis-server --service- ...

  9. Git (一)预设环境和免密登录

    背景 一直用的svn,这段时间换了之后才发现git的强大功能.缺点就是可能上手比较难一点. 接下来就带你Git入门 Git是什么? Git是目前世界上最先进的分布式版本控制系统 Git有什么特点?好用 ...

  10. 查看 Nginx 的日志目录

    即便是 docker 容器,对应的目录也是一样的 > /var/log/nginx/xxx.log