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

思路:以天为状态,则一共有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<int, int> 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. 阿里面试官让我实现一个线程安全并且可以设置过期时间的LRU缓存,我蒙了!

    目录 1. LRU 缓存介绍 2. ConcurrentLinkedQueue简单介绍 3. ReadWriteLock简单介绍 4.ScheduledExecutorService 简单介绍 5. ...

  2. Golang Web入门(3):如何优雅的设计中间件

    摘要 在上一篇文章中,我们已经可以实现一个性能较高,且支持RESTful风格的路由了.但是,在Web应用的开发中,我们还需要一些可以被扩展的功能. 因此,在设计框架的过程中,应该留出可以扩展的空间,比 ...

  3. 刷题记录:[V&N2020 公开赛]TimeTravel

    题目复现链接:https://buuoj.cn/challenges 参考链接:2020 年 V&N 内部考核赛 WriteUp V&N公开赛2020 writeup httpoxy ...

  4. React Hooks: use modal

    useModal: export const useModal = (initTitle: string, initContent: string | React.ReactElement) => ...

  5. search(8)- elastic4s-search-query模式

    上篇提过query模式除对记录的筛选之外还对符合条件的记录进行了评分,即与条件的相似匹配程度.我们把评分放在后面的博文中讨论,这篇我们只介绍query查询. 查询可以分为绝对值查询和全文查询:绝对值查 ...

  6. 使用openmp进行并行编程

    预处理指令pragma 在系统中加入预处理器指令一般是用来允许不是基本c语言规范部分的行为.不支持pragma的编译器会忽略pragma指令提示的那些语句,这样就允许使用pragma的程序在不支持它们 ...

  7. php正则匹配到字符串里面的a标签

    $cont = preg_replace('/<a href=\"(.*?)\".*?>(.*?)<\/a>/i','',$cont);

  8. 2019-2020-1 20199310《Linux内核原理与分析》第一周作业

    1.问题描述 1.1 问题一 Linux文件系统中的文件是数据的集合,文件系统不仅包含着文件中的数据而且还有文件系统的结构,探究根目录下主要文件用途. 1.2 问题二 有一个非常重要的文件(passw ...

  9. 数据挖掘入门系列教程(十一)之keras入门使用以及构建DNN网络识别MNIST

    简介 在上一篇博客:数据挖掘入门系列教程(十点五)之DNN介绍及公式推导中,详细的介绍了DNN,并对其进行了公式推导.本来这篇博客是准备直接介绍CNN的,但是想了一下,觉得还是使用keras构建一个D ...

  10. awk和sed命令

    awk awk是一个强大的编辑工具,可以在无交互的情况下实现相当复杂的文本操作 awk是行处理器: 相比较屏幕处理的优点,在处理庞大文件时不会出现内存溢出或是处理缓慢的问题,通常用来格式化文本信息 a ...