• 【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[2005][13][32];
    int day[13] = {0,31,0,31,30,31,30,31,31,30,31,30,31};
     
    template <typename T> inline void read(T &x) {
        int f = 1; x = 0; char c = getchar();
        for (; !isdigit(c); c = getchar()) { if (c == '-') f = -1; }
        for (; isdigit(c); c = getchar()) x = x * 10 + c - '0';
        x *= f;    
    }
    
    bool is_leap(int yy) {
        if (((yy % 4 == 0) && (yy % 100 != 0)) || (yy % 400 == 0))
            return true;
        else return false;    
    }
    
    bool check(int yy,int mm,int dd) {
        if (is_leap(yy)) day[2] = 29;
        else day[2] = 28;
        if (dd > day[mm]) return false;
        if (yy > 2001) return false;
        if ((yy == 2001) && (mm > 11)) return false;
        if ((yy == 2001) && (mm == 11) && (dd > 4)) return false;
        return true; 
    }
    
    void next_day() {
        if (is_leap(newy)) day[2] = 29;
        else day[2] = 28;
        newd++;
        if (newd > day[newm]) { newd = 1; newm++; }
        if (newm > 12) { newm = 1; newy++; }    
    }
    
    void next_month() {
        newm++;
        if (newm > 12) { newm = 1; newy++; }    
    }
    
    bool dfs(int yy,int mm,int dd) {
        if (f[yy][mm][dd] != -1)
            return f[yy][mm][dd];
        f[yy][mm][dd] = 0;
        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] == 1)
                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,255,sizeof(f));
        f[2001][11][4] = 0;
        read(T);
        
        while (T--) {
            read(y); read(m); read(d);
            puts((dfs(y,m,d))?("YES"):("NO"));    
        }
        
        return 0;
        
    }
  • 相关阅读:
    thinkphp使用ajax程序报500错误
    非隐藏转发和隐藏转发的区别及选择
    表单文件(图片)上传到服务器,权限自动变成363,无法访问
    我收到了互联网应急中心的通报!记sqlmap的正确打开方式。
    css字体可以小于12px!被小米官网打脸
    阿里云CDN添加域名80端口和443端口什么区别?
    网站使用海外服务器,国内访问很慢的解决方案
    linux下设置php文件不区分大小写
    国际化
    Spring boot2.0学习笔记(一)
  • 原文地址:https://www.cnblogs.com/evenbao/p/9306108.html
Copyright © 2020-2023  润新知