HDU 1079 Calendar Game(简单博弈)
Calendar Game
Time Limit: 5000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 1871 Accepted Submission(s): 1065
A player wins the game when he/she exactly reaches the date of November 4, 2001. If a player moves to a date after November 4, 2001, he/she looses the game.
Write a program that decides whether, given an initial date, Adam, the first mover, has a winning strategy.
For this game, you need to identify leap years, where February has 29 days. In the Gregorian calendar, leap years occur in years exactly divisible by four. So, 1993, 1994, and 1995 are not leap years, while 1992 and 1996 are leap years. Additionally, the years ending with 00 are leap years only if they are divisible by 400. So, 1700, 1800, 1900, 2100, and 2200 are not leap years, while 1600, 2000, and 2400 are leap years.
2001 11 3
2001 11 2
2001 10 3
NO
NO
这题就是很简单的博弈题目。
一天一天分析,可以发现,(天数+月份)是偶数时胜的,奇数为负的。但是有两个特殊的是9月30和11月30,这两个也是胜的。
分析的时候,只要一个一个月去看。就可以很容易得到上述的结论。
#include <string.h>
#include <stdio.h>
#include <algorithm>
#include <iostream>
using namespace std;
int main()
{
int y,m,d;
int T;
scanf("%d",&T);
while(T--)
{
scanf("%d%d%d",&y,&m,&d);
if( (d+m)% == || (m == && d == ) || (m == && d == ) )
printf("YES\n");
else printf("NO\n");
}
return ;
}
以前也写过一个直接PN分析的代码,也可以搞出来。
#include<stdio.h>
#include<string.h>
#include<algorithm>
#include<iostream>
using namespace std; int f[][][];
int days[]={,,,,,,,,,,,,};
bool isleap(int y)
{
if(y%==||(y%!=&&y%==))return true;
return false;
} bool ok(int y,int m,int d)//看是不是合法的日期
{
if(isleap(y)&&m==)
{
if(d<=)return true;
else return false;
}
if(d<=days[m])return true;
else return false;
} int solve(int y,int m,int d)
{
if(f[y][m][d]!=-)return f[y][m][d];
if(y==&&m==&&d==)return f[y][m][d]=; if(y>)return f[y][m][d]=;
else if(y==&&m>) return f[y][m][d]=;
else if(y==&&m==&&d>)return f[y][m][d]=; int ty,tm,td;
ty=y;
tm=m;
td=d; if(isleap(y)&&m==)
{
td++;
if(td==)
{
tm=;
td=;
}
}
else
{
td++;
if(td>days[tm])
{
td=;
tm++;
if(tm>)ty++,tm=;
}
}
if(solve(ty,tm,td)==)return f[y][m][d]=; ty=y;
tm=m;
td=d;
tm++;
if(tm>)ty++,tm=;
if(ok(ty,tm,td)&&solve(ty,tm,td)==) return f[y][m][d]=; return f[y][m][d]=; } int main()
{
memset(f,-,sizeof(f));
int y,m,d;
int T;
scanf("%d",&T);
while(T--)
{
scanf("%d%d%d",&y,&m,&d);
if(solve(y,m,d))printf("YES\n");
else printf("NO\n");
}
return ;
}
HDU 1079 Calendar Game(简单博弈)的更多相关文章
- HDU 1079 Calendar Game(博弈找规律)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1079 题目大意:给你一个日期(包含年月日),这里我表示成year,month,day,两人轮流操作,每 ...
- HDU 1079 Calendar Game (博弈)
Calendar Game Time Limit: 5000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Tot ...
- HDU 1079 Calendar Game(规律博弈)
题目链接:https://cn.vjudge.net/problem/HDU-1079 题目: Adam and Eve enter this year’s ACM International Col ...
- HDU 1079 Calendar Game 博弈
题目大意:从1900年1月1日 - 2001年11月4日间选择一天为起点,两个人依次进行两种操作中的任意一种,当某人操作后为2001年11月4日时,该人获胜.问先手是否获胜 操作1:向后移一天 操作2 ...
- HDU 1079 Calendar Game (博弈或暴搜)
题意:给定一个日期,然后 A 和 B 双方进行操作,谁先把日期变成2001年11月04日,将获胜,如果超过该日期,则输了,就两种操作. 第一种:变成下一天,比如现在是2001.11.3 变成 2001 ...
- Hdu 1079 Calendar Game
Problem地址:http://acm.hdu.edu.cn/showproblem.php?pid=1079 一道博弈题.刚开始想用判断P点和N点的方法来打表,但无奈不知是哪里出错,总是WA.于是 ...
- hdu 1846 Brave Game 简单博弈
Problem Description 十年前读大学的时候,中国每年都要从国外引进一些电影大片,其中有一部电影就叫<勇敢者的游戏>(英文名称:Zathura),一直到现在,我依然对于电影中 ...
- HDU 1079 Calendar Game (博弈论-sg)
版权声明:欢迎关注我的博客,本文为博主[炒饭君]原创文章.未经博主同意不得转载 https://blog.csdn.net/a1061747415/article/details/32336485 C ...
- hdu 1079 Calendar Game sg函数 难度:0
Calendar Game Time Limit: 5000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Tot ...
随机推荐
- HDU 1018 Big Number (阶乘位数)
题意: 给一个数n,返回该数的阶乘结果是一个多少位(十进制位)的整数. 思路: 用对数log来实现. 举个例子 一个三位数n 满足102 <= n < 103: 那么它的位数w 满足 w ...
- 20160130.CCPP体系详解(0009天)
程序片段(01):hanoi.c+汉诺塔.c 内容概要:汉诺塔 ///hanoi.c #define _CRT_SECURE_NO_WARNINGS #include <stdio.h> ...
- 基于jquery框架的ajax搜索显示
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html> <hea ...
- 【英语】Bingo口语笔记(14) - 表示“不愉快”
bail on 放弃;背弃
- yii2.0 url 跳转
//转发 $this->render('page1',['id'=>3,'mark'=>2]); //显示page1页面 并传递 id mark 2个参数 //重定向 $thi ...
- iOS NSString的常用用法
//1.创建常量字符串. NSString *astring = @"This is a String!"; //2.创建空字符串,给予赋值. NSString *astrin ...
- vs2012编译出错“LC.exe”已退出解决方法
“LC.exe”已退出,代码为 -1. 解决方法: 将项目Properties下的licenses.licx文件删除,重新编译即可.
- vs2010 please select a valid location in the repository
vs2010 please select a valid location in the repository AnkhSvn版本有问题,我后来使用2.1就ok了记录一下
- 4. 2D绘制与控件绘制
绘制基本图形和文本 绘制图形和文本的基本方法 drawPoint(绘制点).drawLine(绘制直线).drawCircle(绘制圆) drawArc(绘制弧).drawText(绘制文本) pac ...
- html --- javascript --- div --- 拖拽方块
当鼠标拖拽的很快时,光标会走出方块,所以把事件注册在了方块的父节点上, 如有疑问请参照:http://blog.csdn.net/a9529lty/article/details/2708171 使用 ...