HDU 1079 简单博弈

判断下一步能否到达必胜态,如果可以当前状态就是必败态,否则当前状态记为必胜态

 1 #include <cstdio>
 2 #include <cstring>
 3 #include <iostream>
 4 using namespace std;
 5 bool p[115][13][40];
 6 int month[13] = {0 , 31 , 28 , 31 , 30 , 31 , 30 , 31 , 31 , 30 , 31 , 30 , 31};
 7
 8 struct Date{
 9     int y , m , d;
10     Date(int y=0 , int m=0 , int d=0):y(y),m(m),d(d){}
11 };
12
13 bool run(int y)
14 {
15     return y%400 == 0 || (y%4 == 0 && y%100 != 0);
16 }
17
18 bool ok(int y , int m , int d)
19 {
20     if(run(y)) month[2]=29;
21     bool flag;
22     if(d > month[m]) flag = false;
23     else flag = true;
24     month[2] = 28;
25     return flag;
26 }
27
28 Date getLastDay(int y , int m , int d)
29 {
30     Date tmp;
31     tmp.y = y , tmp.m = m , tmp.d =d;
32     if(run(y)) month[2]=29;
33     if(d == 1){
34         if(m == 1){
35             tmp.y--;
36             tmp.d=31 , tmp.m =12;
37         }else{
38             tmp.m--;
39             tmp.d = month[tmp.m];
40         }
41     }
42     else tmp.d--;
43     month[2] = 28;
44     return tmp;
45 }
46
47 Date get_next_month(int y , int m , int d)
48 {
49     Date tmp;
50     tmp.y = y , tmp.m = m , tmp.d =d;
51     if(m == 12) tmp.m=1 , tmp.y+=1;
52     else tmp.m+=1;
53     return tmp;
54 }
55
56 void init()
57 {
58     memset(p , 0 , sizeof(p));
59     p[101][11][4] = true;
60     Date cur = Date(2001 , 11 , 4);
61     while(1){
62         Date la = getLastDay(cur.y , cur.m , cur.d);
63
64         Date next_month = get_next_month(la.y , la.m , la.d);
65         bool p1 = p[cur.y-1900][cur.m][cur.d];
66         bool p2 = false;
67
68         if(ok(next_month.y , next_month.m , next_month.d))
69             p2 = p[next_month.y-1900][next_month.m][next_month.d];
70         if(p1 || p2) p[la.y-1900][la.m][la.d] = false;
71         else p[la.y-1900][la.m][la.d] = true;
72
73         cur.y = la.y , cur.m = la.m , cur.d = la.d;
74         if(cur.y == 1900 && cur.m == 1 && cur.d == 1) break;
75     }
76 }
77
78 int main()
79 {
80   //  freopen("a.in" , "r" , stdin);
81     int T;
82     scanf("%d" , &T);
83     init();
84
85     while(T--)
86     {
87         int y , m ,d;
88         scanf("%d%d%d" , &y , &m , &d);
89
90         if(p[y-1900][m][d]) puts("NO");
91         else puts("YES");
92     }
93     return 0;
94 }
时间: 2024-10-14 08:31:42

HDU 1079 简单博弈的相关文章

HDU 1847——简单博弈

题目: Description 大学英语四级考试就要来临了,你是不是在紧张的复习?也许紧张得连短学期的ACM都没工夫练习了,反正我知道的Kiki和Cici都是如此.当然,作为在考场浸润了十几载的当代大学生,Kiki和Cici更懂得考前的放松,所谓“张弛有道”就是这个意思.这不,Kiki和Cici在每天晚上休息之前都要玩一会儿扑克牌以放松神经. “升级”?“双扣”?“红五”?还是“斗地主”? 当然都不是!那多俗啊~ 作为计算机学院的学生,Kiki和Cici打牌的时候可没忘记专业,她们打牌的规则是这

HDU 1846 Brave Game (简单博弈)

HDU 1846 Brave Game (简单博弈) ACM 题目地址: HDU 1846 Brave Game 题意: 中文. 分析: 博弈入门. 如果n=m+1,因为最多取m个,所以先拿的人拿多少个,后拿的人能全拿走. 所以判断n%(m+1)即可. 代码: /* * Author: illuz <iilluzen[at]gmail.com> * File: 1846.cpp * Create Date: 2014-09-20 10:05:26 * Descripton: game */ #

[简单博弈] hdu 1525 Euclid&#39;s Game

题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=1525 Euclid's Game Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 1832    Accepted Submission(s): 808 Problem Description Two players, Stan and

hdu 2999 sg函数(简单博弈)

Stone Game, Why are you always there? Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 393    Accepted Submission(s): 132 Problem Description "Alice and Bob are playing stone game...""E

hdu 4763 stone(博弈)

F - Stone Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u Submit Status Practice HDU 4764 Description Tang and Jiang are good friends. To decide whose treat it is for dinner, they are playing a game. Specifically, Tang an

HDU 1079 Calendar Game (博弈论-sg)

Calendar Game Problem Description Adam and Eve enter this year's ACM International Collegiate Programming Contest. Last night, they played the Calendar Game, in celebration of this contest. This game consists of the dates from January 1, 1900 to Nove

hdu 2176(简单小尼姆)(小尼姆的先手取子方式)

取(m堆)石子游戏 Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 1728    Accepted Submission(s): 1006 Problem Description m堆石子,两人轮流取.只能在1堆中取.取完者胜.先取者负输出No.先取者胜输出Yes,然后输出怎样取子.例如5堆 5,7,8,9,10先取者胜,先取者第1次

HDU 1253 (简单三维广搜) 胜利大逃亡

奇葩!这么简单的广搜居然爆内存了,而且一直爆,一直爆,Orz 而且我也优化过了的啊,尼玛还是一直爆! 先把代码贴上睡觉去了,明天再来弄 1 //#define LOCAL 2 #include <iostream> 3 #include <cstdio> 4 #include <cstring> 5 #include <queue> 6 #include <cmath> 7 using namespace std; 8 9 struct Poin

hdu 3032(博弈sg函数)

题意:与原来基本的尼姆博弈不同的是,可以将一堆石子分成两堆石子也算一步操作,其它的都是一样的. 分析:由于石子的堆数和每一堆石子的数量都很大,所以肯定不能用搜索去求sg函数,现在我们只能通过找规律的办法求得sg的规律. 通过打表找规律可以得到如下规律:if(x%4==0) sg[x]=x-1; if(x%4==1||x%4==2) sg[x]=x; if(x%4==3) sg[x] = x+1. 打表代码: #include<iostream> #include<cstdio> #