Lucky and good Months by Gregorian Calendar (POJ 3393)

Source: Internet
Author: User

Approximate test instructions:

A popular Science article, article 80% is useless information, because all is common sense, but also have to see, because 20% is ordinary people do not know the historical knowledge.

Defined:

Goog Month: Month of Monday for the first business day

Luckly Month: Month of Friday for the last working day

Q: Given a time-closed interval of the high Gregorian calendar in a Gregorian calendar (that is, the end of the month is included)

"Start year, month" ~ "End year, month"

How many goog month are there in this time interval, and how many luckly month

Article Highlights:

Gregorian calendar Gregorian High is now widely used in the Gregorian calendar (Western calendar), hereinafter referred to as GC

The GC starts at 1 January 1, the date of Saturday

GC common year has 365 days, leap year 366 days (February more than 1 days)

GC has 12 months, the number of days of the month and the current use of Western calendar consistent

GC before 1582 (excluding 1582), a leap year if it can be divisible by 4

After 1582 years (including 1582), the GC judges the criteria for a leap year (any one of the following):

(1) can be divisible by 4, but not divisible by 100;

(2) can be divisible by 400.

For historical reasons, the GC prescribes 1700 as a leap year unconditionally

Due to historical reasons, the GC stipulates that September 3, 1752 ~ 13th a total of 11 days does not exist, that is, September 1752 only 19 days

GC has 7 days in a week, sorted for Sun,mon,tue,wed,thu,fri,sat, and now Monday, where Mon to Fri for weekdays, Sun and Sat for rest day

#include <cstdio>#include<iostream>#include<cstring>using namespacestd;intmnum[ -]={0, to, -, to, -, to, -, to, to, -, to, -, to};intrnum[ -]={0, to, in, to, -, to, -, to, to, -, to, -, to};intnu52[ -]={0, to, in, to, -, to, -, to, to, +, to, -, to};intrr[10010],rr_b[10010],good[10010][ -],lucky[10010][ -];intRunintx) {    if(Rr_b[x])returnRr[x]; RR_B[X]=1; if(x<1582&&x%4==0) rr[x]=1; Else if(x==1700) rr[x]=1; Else if(% -==0) rr[x]=1; Else if(%4==0&&x% -!=0) rr[x]=1; returnrr[x];}voidWork () {intday=5;  for(intI=1; i<=10000; i++)//Cycle Year    {         for(intj=1; j<= A; j + +)//Cycle Month        {            if(j==1)//difference between January and the ordinary month{Good[i][j]=good[i-1][ A]; LUCKY[I][J]=lucky[i-1][ A]; }            Else{Lucky[i][j]=lucky[i][j-1]; GOOD[I][J]=good[i][j-1]; }            if(i==1752)//1752            {                  intGd= (day+1)%7, ld= (Day+nu52[j])%7; if(gd==1|| gd==6|| gd==0) good[i][j]+=1; if(ld==5|| ld==6|| ld==0) lucky[i][j]+=1; Day= (Day+nu52[j])%7; }            Else if(Run (i))//Normal leap year            {                intGd= (day+1)%7, ld= (Day+rnum[j])%7; if(gd==1|| gd==6|| gd==0) good[i][j]+=1; if(ld==5|| ld==6|| ld==0) lucky[i][j]+=1; Day= (Day+rnum[j])%7; }            Else//average year            {                intGd= (day+1)%7, ld= (Day+mnum[j])%7; if(gd==1|| gd==6|| gd==0) good[i][j]+=1; if(ld==5|| ld==6|| ld==0) lucky[i][j]+=1; Day= (Day+mnum[j])%7; }        }    }}intMain () {intx,xm,y,ym,t;    Work (); scanf ("%d",&T);  while(t--) {scanf ("%d%d%d%d",&x,&xm,&y,&ym); if(xm==1) printf ("%d%d\n", lucky[y][ym]-lucky[x-1][ A],good[y][ym]-good[x-1][ A]); Elseprintf"%d%d\n", lucky[y][ym]-lucky[x][xm-1],good[y][ym]-good[x][xm-1]); }//Notice that XM is January.    return 0;}
View Code

Lucky and good Months by Gregorian Calendar (POJ 3393)

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.