HDOJ Calendar Game 1079【博弈】

Calendar Game

Time Limit: 5000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)

Total Submission(s): 3097    Accepted Submission(s): 1809

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 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. 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
2001 11 3
2001 11 2
2001 10 3 

Sample Output

YES
NO
NO 

Source

Asia 2001, Taejon (South Korea)

Recommend

We have carefully selected several similar problems for you:  1517 1404 2147 1524 1729

博弈。

转化成了奇偶博弈

讨论区这个讲解不错:

说一下此题的为什么:

1.把月和日的和看做一个数sum,记为sum= (m + d),其中m为月份,d为日期。

显然sum不是奇数就是偶数,sum一次变化后是奇数还是偶数呢?

sum的变化有三种情况:

(1)m + (d + 1) 即日期加一,且没有超出本月的日期,变化后为奇数。

(2)(m + 1) + d 即月份加一(12月每一天都可到1月的一天),变化后为奇数。

(3)(m + 1) + 1 即日期加一,但是超出本月的日期,变化后暂时不知道是奇数还是偶数。

由上面的(1)(2)(3)知道,如果sum为偶数且(1)或(2)可行,那么sum必然还是偶数。

如果sum只有变化(3)可行,则使得这样的sum成立的m和d只能是如下几个:

(m,d)={(1,31)(3,31)(5,31)(8,31)(10,31)}.

如果sum为偶数且只有变化(3)可行,则使得这样的sum成立的m和d只能是如下几个:

(m,d)={(1,31)(3,31)(5,31)}.为了使 ((m + 1) + 1)=(m + 2) 为奇数,则

m必须为奇数,显然{(1,31)(3,31)(5,31)}的所有m都为奇数,即如果sum为偶数且

只有变化(3)可行时,sum变化后也为奇数。

所以可以得到如下结论:

如果sum为偶数,那么一次变化后总可以使得sum变为奇数。

2.如果sum是奇数,经过一次变化之后是不是可以仍然是奇数呢?

由于sum的三种变化中,(1)(2)使得sum变化之后成为了偶数,所以为了满足让其仍然为奇数,

显然,我们只能寄希望于变化(3).而能进行变化(3)的(m,d)只有如下几个:

(m,d)={(1,31)((2,28)or(2,29)(leap year))(3,31)(4,30)(5,31)

(6,30)(7,31)(8,31)(9,30)(10,31)(11,30)(12,31)}.

由于sum为奇数,那么m和d的组合只能是如下几个:

(m,d)={(2,29)(8,31)(9,30)(10,31)(11,30)(12,31)}.同样为了使 (m + 2) 为奇数,

则m必须为奇数,显然只有{(9,30)(11,30)}的m为奇数,即如果sum为奇数,经过一次变化之

后可以仍然是奇数的(m,d)只有{(9,30)(11,30)}.

3.以上飞了很多的唾沫,显然都是一些铺垫,我们需要和本题来一个完美的对接。

题目中我们的目的是使得 Adam (moving first)赢,目标状态的sum = 15 = (11 + 4),

目标sum为一个奇数,如果初始数据的sum为偶数或者{(9,30)(11,30)},则Adam 总是可以

将一个sum为奇数的(m,d)抛给Eve.那么Eve就永远只有将奇数sum变化成偶数sum的份,

也就是说Eve不可能到达目标状态。反过来如果 Adam 一开始没有得到偶数或者{(9,30)(11,30)}

状态,那么Adam就把偶数的sum抛给了Eve,Eve得到了控制权。Adam自然也不可能到目标状态。

可能有人会想,Adam把奇数的sum抛给了Eve,那么Eve就不知道把奇数的sum继续变成奇数给

Adam吗?

对于这个问题,只要Adam不留余地就可以了,因为(9,30)前一个状态可能是{(8,30)(9,29)}.

而这两个状态是可以绕过(9,30)的,同理也可以绕过(11,30).

所以只要判断是否可以到奇数的状态即可

#include <stdio.h>
#include <math.h>
#include <vector>
#include <queue>
#include <string>
#include <string.h>
#include <stdlib.h>
#include <iostream>
#include <algorithm>

using namespace std;

int main()
{
    int t;
    scanf("%d",&t);
    while(t--){
        int y,m,d;
        scanf("%d%d%d",&y,&m,&d);
        if((m+d)%2==0||m==9||m==11&&d==30)
            printf("YES\n");
        else
            printf("NO\n");
    }
    return 0;
}

版权声明:本文为博主原创文章,转载请注明出处。

时间: 2024-12-31 03:44:48

HDOJ Calendar Game 1079【博弈】的相关文章

【HDOJ 4764】 Stone (博弈)

[HDOJ 4764] Stone (博弈) Stone Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 1090    Accepted Submission(s): 761 Problem Description Tang and Jiang are good friends. To decide whose treat it is

HDU 1079 Calendar Game(博弈找规律)

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1079 题目大意:给你一个日期(包含年月日),这里我表示成year,month,day,两人轮流操作,每次操作可以将month+1但是,如果下月没有对应的day则只能对day+1(超过该月日数就进入下月一日),或者就day+1.谁最后到达2001.11.4这个日期就是胜者,问先手的人是否能获胜. 解题思路:这个就用上面的P/N分析,一个个月份日期对应的标记上P或N(很快会发现规律只用找每月特定几天),

HDU1079 POJ1082 Calendar Game【博弈】

题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=1079 题目大意: 有一个日期游戏,胜利时间是2001年11月4日.玩家可以从当前日期移动到下一天,也可以移动到 下一个月的今天,比如从2000年3月3日可以移动到2000年3月4日,也可以移动到2000年4月3日. 当然,移动到下一个月的当前日期的前提是那一天是存在的,比如说2001年1月31日,只能移动到 2001年2月1日,而不能移动到2001年2月31日,因为那天不存在.问:给你一个日期,玩

Light OJ 1393 Crazy Calendar (尼姆博弈)

C - Crazy Calendar Time Limit:4000MS     Memory Limit:32768KB     64bit IO Format:%lld & %llu Submit Status Practice LightOJ 1393 Description 2011 was a crazy year. Many people all over the world proposed on 11-11-11, married on 11-11-11, some even w

HDOJ

第一篇 1001 这个就不用说了吧1002 简单的大数1003 DP经典问题,最大连续子段和1004 简单题1005 找规律(循环点)1006 感觉有点BT的题,我到现在还没过1007 经典问题,最近点对问题,用分治1008 简单题1009 贪心1010 搜索题,剪枝很关键1011 1012 简单题1013 简单题(有个小陷阱)1014 简单题1015 可以看作搜索题吧1016 经典的搜索1017 简单数学题1018 简单数学题1019 简单数学题1020 简单的字符串处理1021 找规律的数学

hdoj分类(转)

注:网上搜的 第一篇 1001 这个就不用说了吧 1002 简单的大数 1003 DP经典问题,最大连续子段和 1004 简单题 1005 找规律(循环点) 1006 感觉有点BT的题,我到现在还没过 1007 经典问题,最近点对问题,用分治 1008 简单题 1009 贪心 1010 搜索题,剪枝很关键 1011 1012 简单题 1013 简单题(有个小陷阱) 1014 简单题 1015 可以看作搜索题吧 1016 经典的搜索 1017 简单数学题 1018 简单数学题 1019 简单数学题

转载:hdu 题目分类 (侵删)

转载:from http://blog.csdn.net/qq_28236309/article/details/47818349 基础题:1000.1001.1004.1005.1008.1012.1013.1014.1017.1019.1021.1028.1029. 1032.1037.1040.1048.1056.1058.1061.1070.1076.1089.1090.1091.1092.1093. 1094.1095.1096.1097.1098.1106.1108.1157.116

HDU 题目分类

基础题:1000.1001.1004.1005.1008.1012.1013.1014.1017.1019.1021.1028.1029.1032.1037.1040.1048.1056.1058.1061.1070.1076.1089.1090.1091.1092.1093.1094.1095.1096.1097.1098.1106.1108.1157.1163.1164.1170.1194.1196.1197.1201.1202.1205.1219.1234.1235.1236.1248.1

(转)

来源:http://blog.csdn.net/vsooda/article/details/7293655 1001       这个就不用说了吧1002       简单的大数1003       DP经典问题,最大连续子段和1004       简单题1005       找规律(循环点)1006       感觉有点BT的题,我到现在还没过1007       经典问题,最近点对问题,用分治1008       简单题1009       贪心1010       搜索题,剪枝很关键10