zoukankan      html  css  js  c++  java
  • 【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;
        
    }
  • 相关阅读:
    VC++中如何让RadioButton分组,并且互斥
    CString 中的SpanIncluding 和SpanExcluding 用法
    vs2003属性窗口空白的问题
    查看虚函数表
    TabControl控件用法图解
    ADO+MFC数据库编程常用语句
    VC++ MFC SQL ADO数据库访问技术使用的基本步骤及方法
    ODBC、OLEDB、ADO、SQL的关系
    C++虚函数及虚函数表解析
    poj 2114 Boatherds 树的分治
  • 原文地址:https://www.cnblogs.com/evenbao/p/9306108.html
Copyright © 2011-2022 走看看