HDU_1079_思維題

來源:互聯網
上載者:User

標籤:

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 DescriptionAdam 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. 

 

InputThe 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.  

 

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

 

Sample OutputYES 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_思維題

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.