HDU_1079_思维题

Posted Jason333

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了HDU_1079_思维题相关的知识,希望对你有一定的参考价值。

Calendar Game

Time Limit: 5000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 3628    Accepted Submission(s): 2163


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
 
想说这道题是个神题(目前这个水平看来)。。。应该有别的思路,但是这个题解的思路我是完全没想到。。。
思路:把month和day看作一个整体sum=month+day,按照题目规则,可以跳到当前日期的下一天,后者跳到下个月对应的当前这天,即month+1或者day+1,那么sum的奇偶性发生变化,11月4日对应的sum为奇数,那么要赢的话,就一直把奇数抛给后者,如果是普通的日期(不是每个月边界)sum为奇数,那么抛出的一定是偶数,sum为偶数,抛出的一定是奇数。边界的话:
(1.31)->(2.1)
(2.28)->(3.28)||(3.1)(平年)
(2.29)->(3.29)||(3.1)(闰年)
(3.31)->(4.1)
(4.30)->(5.1)||(5.30)
(5.31)->(6.1)
(6.30)->(7.1)||(7.30)
(7.31)->(8.1)||(8.31)
(8.31)->(9.1)
(9.30)->(10.1)||(10.30)
(10.31)->(11.1)
(11.30)->(12.1)||(12.30)
(12.31)->(1.1)||(1.31)
其中奇数能抛出奇数的有(9.30)和(11.30),(9.30)的前驱为(9.29)和(8.30),(11.30)的前驱为(10.30)和(11.29),即是说这两个日期是可以被绕过的,那么便有当前位置在这两个日期的人一定可以赢。
综上,若前者初始位置的sum为偶数,则前者一定可以赢,一直让后者走的时候位置在奇数,走后到达偶数;若前者初始位置为(9.30)或(11.30),他也可以抛出奇数。
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;


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

 

以上是关于HDU_1079_思维题的主要内容,如果未能解决你的问题,请参考以下文章

HDU6038-Function-数学+思维-2017多校Team01

学习方法_2011年编写和锻炼的思维题

HDU_6695 Welcome Party 思维

HDU 2199 (二分&三分 _A题)解题报告

HDU 2013(递推&递归_D题)解题报告

XDOJ_1079_暴力技巧