zoukankan      html  css  js  c++  java
  • POJ

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

    Sample Output

    YES
    NO
    NO

     1 /*
     2 分析:
     3 设S为输点 Y为赢点
     4 S        Y
     5 11 4     11 3
     6 11 2     11 1
     7 10 31     10 30
     8 10 5     10 4
     9 10 1     9 30*      9月30日后只能是10月1日因为没有9月31日
    10          9 29*        9月29日可以到10月29日
    11 9 28     9 27*
    12 9 2         9 1
    13 8 31     8 30
    14 8 1        7 31
    15 
    16 
    17 7 2         7 1
    18          6 30*
    19 6 29     6 28
    20 6 1         5 31
    21 5 30     5 29
    22 5 2         5 1
    23          4 30*
    24 4 29     4 28
    25 4 3         4 2
    26 4 1         3 31
    27 3 30     3 29
    28 3 2         3 1
    29 2 29*     2 28*
    30 2 27     2 26
    31 2 1         1 31
    32 1 2         1 1
    33 12 31     12 30
    34 12 29     12 28
    35 12 1     11 30
    36          11 29*
    37 11 28     11 27
    38 11 2     11 1
    39 如此分析可得到一个周年的循环,这个周期与年份无关
    40 为什么呢?因为闰年的2 28是一个必胜点 2 29是一个必败点
    41 观察所有必胜点发现其月与日之和基本为偶数,仅有两个例外
    42 例外的分别是11 30与9 30.这样就可以AC题了!*/
    43 #include <iostream>
    44 #include <stdio.h>
    45 using namespace std;
    46 int main(){
    47     int n,year,month,day;
    48     scanf("%d",&n);
    49     while(n--){
    50         scanf("%d%d%d",&year,&month,&day);
    51         if((month+day)%2==0||(day==30&&(month==9||month==11)))
    52             printf("YES
    ");
    53         else printf("NO
    ");
    54     }
    55     return 0;
    56 }
  • 相关阅读:
    Java基础面试题总结
    mysql面试题总结
    记7.9面试题
    深入理解Java虚拟机学习笔记(三)-----类文件结构/虚拟机类加载机制
    jvm类加载子系统
    多线程与高并发基础三
    多线程与高并发基础二
    多线程与高并发基础一
    多线程与高并发笔记一
    Unknown initial character set index '255' received from server. Initial client character set can be forced via the 'characterEncoding' property.
  • 原文地址:https://www.cnblogs.com/z-712/p/7324482.html
Copyright © 2011-2022 走看看