【POJ1082】Calendar Game (博弈)
【题目】
|
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 November 4, 2001, the contest day. The game starts by randomly choosing a date from this interval. Then, the players, Adam and Eve, make moves in their turn with Adam moving first: Adam, Eve, Adam, Eve, etc. There is only one rule for moves and it is simple: from a current date, a player in his/her turn can move either to the next calendar date or the same day of the next month. When the next month does not have the same day, the player moves only to the next calendar date. For example, from December 19, 1924, you can move either to December 20, 1924, the next calendar date, or January 19, 1925, the same day of the next month. From January 31 2001, however, you can move only to February 1, 2001, because February 31, 2001 is invalid.
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. Input The input consists of T test cases. The number of test cases (T ) is given in the first line of the input file. Each test case is written in a line and corresponds to an initial date. The three integers in a line, YYYY MM DD, represent the date of the DD-th day of MM-th month in the year of YYYY. Remember that initial dates are randomly chosen from the interval between January 1, 1900 and November 4, 2001.
Output Print exactly one line for each test case. The line should contain the answer "YES" or "NO" to the question of whether Adam has a winning strategy against Eve. Since we have T test cases, your program should output totally T lines of "YES" or "NO".
Sample Input 3 Sample Output YES |
【题意】
从某年某月某天开始两个人轮流开始将日期推进,推进方法有两种,1.推进到第二天 2.推进到下个月的这一天。谁到达2001.11.4谁赢,谁超过了谁输。
【分析】
一开始想到了最暴力的方法,就是递归找状态(应该是能做出来的)。然而看了大神的29行代码后,我方了!!方了!!
先看看大神的思路:
分析:np问题,我们设月号加日号等于d,对于第二种推进方式,会改变d的奇偶性。(因为月的奇偶变了,日的奇偶没变,和的奇偶就变了)。对于第一种推进方式,如果推进后还在同一个月份,那么会改变d的奇偶性。(因为月的奇偶没变,日的变了,和的奇偶就变了)。第一种推进方式,跨月份的时候,有些会改变,有些不会改变。有31天、29天的月份会变,30天、28天的不会变,其中对于d为偶的情况(2月28,4、6月30)可以利用第二中方式变为奇。
由此可见对于绝大部分情况来说d的奇偶是轮流出现的,最终必败态是11月4日奇态。所有的偶态均可到达奇态,对于d为奇的9、11月30也可以到达奇态。其余奇态只能到达偶态。如果把偶态和9.30和11.30划入集合A,其余划入集合B,那么对于A的所有元素均有办法到达集合B。而B中元素只能到达集合A,无法到达集合B。且11.4属于B。所以,A中元素为必胜,B中为必败。(还需仔细考虑快到2001.11.4的那些日子,幸好也没有出现任何意外)
我来试着按着他的思路推一遍。
假设:偶态(日加月为偶数),9.30和11.30为必胜态,其余为必败态。
我们只要证明:
·1、2001.11.4为必败态。(别人给你这个状态相当于别人先一步走到这个状态,你输了)这点显而易见,不需要证明。
·2、所有的必胜态都能到达某一必败态。
·3、所有的必败态都只能到达必胜态。
证明2:所有的必胜态都能到达某一必败态。
1、当为偶态,若能走到下一个月,则能走到必败态。
2、当为偶态,不能走到下一个月,走到下一天,则能走到必败态。
3、当为9.30->10.1,当为11.30->12.1
证明3:所有的必败态(除9.30 11.30的奇态)都只能到达必胜态。
除了那两天,走到下一天还是下一个月都会是偶态。
所以假设成立。
代码如下:
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
#define Maxn 1010 int main()
{
int T;
scanf("%d",&T);
while(T--)
{
int y,m,d;
scanf("%d%d%d",&y,&m,&d);
if((m==||m==)&&d==) printf("YES\n");
else if((m%)==(d%)) printf("YES\n");
else printf("NO\n");
}
return ;
}
[POJ1082]
2016-04-24 15:01:14
【POJ1082】Calendar Game (博弈)的更多相关文章
- poj1082 Calendar Game (博弈)
题意是:Adam和Eve两人做游戏,开始给出一个日期,截止日期是2011.11.4,游戏规则如下: 每个人只能将天数增加一天或者将月份增加一天.如果下个月没有这一天,那么只能增加天数. 游戏胜利定义为 ...
- Crazy Calendar (阶梯博弈变形)
2011 was a crazy year. Many people all over the world proposed on 11-11-11, married on 11-11-11, som ...
- UVA 1557 - Calendar Game(博弈dp)
UVA 1557 - Calendar Game 题目链接 题意:给定一个日期,两个人轮流走,每次能够走一月或者一天,问最后谁能走到2001.11.4这个日子 思路:记忆化搜索,对于每一个日期,假设下 ...
- uva 1557 - Calendar Game(博弈)
option=com_onlinejudge&Itemid=8&page=show_problem&problem=4332" target="_blank ...
- [POJ1082]Calendar Game
题目大意: 日历上博弈,从给定的日期,按照下述规则跳转日期: 1.跳到第二天: 2.调到下个月相同的日期(如果没有就不能跳转). 刚刚好跳到2001年11月4日的人胜,跳转时不能跳到2001年11月4 ...
- 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 ...
- LightOJ 1393 Crazy Calendar(博弈)题解
题意:r*c方格中,每个格子有一定石子,每次移动每格任意数量石子,只能向下或者向右动一格,不能移动为败 思路:显然是Nim,到右下曼哈顿距离为偶数的不用管,因为先手动一下后手动一下最后移到右下后还是先 ...
- Light OJ 1393 Crazy Calendar (尼姆博弈)
C - Crazy Calendar Time Limit:4000MS Memory Limit:32768KB 64bit IO Format:%lld & %llu Su ...
随机推荐
- PureMVC(JS版)源码解析(七):Mediator类
之前的博文中,我们分析了SimpleCommand类和MacroCommand类,这两个类用作"业务逻辑(business logic)"处理,今天,我们讲一些和UI界面相关联的M ...
- JSPatch 成长之路
在这次 GMTC 大会上,我见到了 JSPatch 的作者 bang.在这之前我就和他在网上认识并聊过很多次,bang 也在这个公众号上投稿发表了多篇关于 JSPatch 的文章,包括:JSPatch ...
- ObjectInputStream ObjectOutStream
1:不能多次read 2:read 与write操作必须一对一
- sybase SA密码重置
sa 密码忘记解决之道: su - sybase cd ASE/install vi RUN_etoh2 在文件的末尾加入 -psa \ 停止原数据库服务 由于密码遗忘,所以只能通过kill进程停止服 ...
- jQuery滑动并响应事件
jQuery滑动并打开指定页面: <!DOCTYPE html> <html> <head> <script src="http://code.jq ...
- thinkphp3.2.x版本中图片上传缩略图的解决方案
调用方式很简单 get_sc($cover_id,[$width=180,$height=auto,$cut]) @param $cover_id 图片ID___ @param $width 宽度__ ...
- MySQL数字类型中的三种常用种类
数字类型 MySQL数字类型按照我的分类方法分为三类:整数类.小数类和数字类. MySQL数字类型之一我所谓的“数字类” 就是指 DECIMAL 和 NUMERIC,它们是同一种类型.它严格的说不是一 ...
- 使用linq获得当前文件夹下的下一级满足条件的文件夹
使用linq获得当前文件夹下的下一级满足条件的文件夹. SPFolderCollection subAlbums = Folder.SubFolders; ...
- mvc性能优化
mvc性能优化 (1)移动设备卡顿问题 -1请求方式 在mvc中GET请求有问题,出现错误 在MVC中在进行GET请求获取JSON数据时,需要进行如下设置: return Json("&qu ...
- 283. Move Zeroes(C++)
283. Move Zeroes Given an array nums, write a function to move all 0's to the end of it while mainta ...