UVA 1557-calendar Game (game)

Source: Internet
Author: User

option=com_onlinejudge&itemid=8&page=show_problem&problem=4332 "target=" _blank "style=" "> Topic Link: UVA 1557-calendar Game

Topic: Given a date, each can choose to add one months, or add a day, plus one months on the premise that the next one months have a corresponding date, for example, 1.30 plus one months into 2.30 is not legal. The date is capped at 2001.11.4. Two persons take turns to operate. Cannot be manipulated as a failure.

Problem-solving ideas: Dp[y][m][d] Indicates whether the corresponding date is the initiator win.

Pre-processing can be, attention to detail, including leap years and so on. Share the code.

#include <cstdio>#include <cstring>#include <algorithm>using namespace STD;Const intY = the;Const intD = the;Const intM = *;Const intMonth[d] = {0, to, -, to, -, to, -, to, to, -, to, -, to};intDP[Y][D][M];BOOLIs_year (intY) {if(Y% -==0&& y% -==0)return true;if(Y%4==0&& y% -)return true;return false;}intGet_day (intYintm) {if(Y = =2001&& m = = One)return 4;if(M = =2&& is_year (y))return  in;returnMONTH[M];}BOOLJudge_day (intYintMintD) {if(Y >101)return false;if(Y = =101&& m > One)return false;if(Y = =101&& m = = One&& d >4)return false;return true;}BOOLGetnext_day (int& YY,int& MM,int& DD,intYintMintDintType) {if(type)        {dd = D; mm = m +1;if(mm > A) {yy = y +1; MM =1; }Elseyy = y;if(dd > Get_day (yy +1900, m))return false; }Else{dd = d +1;if(dd > Get_day (y +1900, m)) {DD =1; mm = m +1; }Elsemm = m;if(mm > A) {yy = y +1; MM =1; }Elseyy = y; }returnJudge_day (yy, MM, DD);}intSG (intYintMintD) {if(Dp[y][m][d]! =-1)returnDP[Y][M][D]; DP[Y][M][D] =0;intYY, MM, DD;if(Getnext_day (yy, MM, DD, Y, M, D,0)) {if(SG (yy, mm, dd) = =false) Dp[y][m][d] =1; }if(Getnext_day (yy, MM, DD, Y, M, D,1)) {if(SG (yy, mm, dd) = =false) Dp[y][m][d] =1; }returnDP[Y][M][D];}voidInit () {memset(DP,-1,sizeof(DP)); dp[101][ One][4] =0; for(inti =0; I <=101; i++) {intLimit_month = (i = =101?

One: A); for(intj =1; J <= Limit_month; J + +) {intLimit_day = Get_day (1900+i, J); for(intD =1; D <= Limit_day; d++) SG (i, J, D); } }}intMain () {init ();intCAs, y, M, D;scanf("%d", &cas); while(cas--) {scanf("%d%d%d", &y, &m, &d);printf("%s\n", dp[y-1900][M][D]?

"YES" : "NO"); } return 0;}

UVA 1557-calendar Game (game)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.