HDU-1079 Calendar Game
Calendar Game
给出一个终止日期和开始日期,两个人每次只能有两种方式移动的合法日期,如果日期不合法,则不能移动:
-
移动到当前日期的下一天
-
移动到当前日期的下一月同一天
先到达终止日期的获胜,不允许到达终止日期后的日期
博弈论
简单的一个博弈图分析,分析一下必胜态和必输态即可,日期处理上面比较繁琐,状态用map_sg来表示,0表示必输态,1表示必胜态
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <string>
#include <queue>
#include <functional>
#include <map>
#include <set>
#include <cmath>
#include <cstring>
#include <deque>
#include <stack>
using namespace std;
typedef long long ll;
#define pii pair<int, int>
const ll maxn = 2e5 + 10;
const ll inf = 1e17 + 10;
int m[13] = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
bool r_year(int year)
{
return (year % 400 == 0) || (year % 4 == 00 && year % 100 != 0);
}
struct node
{
int year, month, day;
node(){}
node(int _y, int _m, int _d){year = _y; month = _m; day = _d;}
bool fit()
{
if(month == 13) month = 1, year++;
if(r_year(year)) m[2] = 29;
bool flag = true;
if(day > m[month] || day < 1) flag = false;;
m[2] = 28;
return flag;
}
bool operator < (const node& a) const
{
if(a.year != year) return year < a.year;
if(a.month != month) return month < a.month;
return day < a.day;
}
void operator --(int)
{
day--;
if(day == 0)
{
month--;
if(month == 0)
{
year--;
month = 12;
}
if(r_year(year)) m[2] = 29;
day = m[month];
m[2] = 28;
}
}
};
map<node, int>sg;
int main()
{
node r(2001, 11, 4), l(1900, 1, 0);
int cur = 1;
node pre = r, last(2001, 11, 5);
r--;
while(l < r)
{
int f = 1;
f = min(f, sg[pre]);
node nex = r;
nex.month += 1;
if(nex.fit() && nex < last)
f = min(f, sg[nex]);
if(f) sg[r] = 0;
else sg[r] = 1;
pre = r;
r--;
}
int t;
scanf("%d", &t);
while(t--)
{
int a, b, c;
scanf("%d%d%d", &a, &b, &c);
node now(a, b, c);
printf("%s\n", sg[now] == 0 ? "NO" : "YES");
}
return 0;
}

浙公网安备 33010602011771号