ZOJ 3876 May Day Holiday 蔡勒公式

來源:互聯網
上載者:User

標籤:

                                               H - May Day Holiday

Description

As a university advocating self-learning and work-rest balance, Marjar University has so many days of rest, including holidays and weekends. Each weekend, which consists of Saturday and Sunday, is a rest time in the Marjar University.

The May Day, also known as International Workers‘ Day or International Labour Day, falls on May 1st. In Marjar University, the May Day holiday is a five-day vacation from May 1st to May 5th. Due to Saturday or Sunday may be adjacent to the May Day holiday, the continuous vacation may be as long as nine days in reality. For example, the May Day in 2015 is Friday so the continuous vacation is only 5 days (May 1st to May 5th). And the May Day in 2016 is Sunday so the continuous vacation is 6 days (April 30th to May 5th). In 2017, the May Day is Monday so the vacation is 9 days (April 29th to May 7th). How excited!

Edward, the headmaster of Marjar University, is very curious how long is the continuous vacation containing May Day in different years. Can you help him?

Input

There are multiple test cases. The first line of input contains an integer T indicating the number of test cases. For each test case, there is an integer y (1928 <= y <= 9999) in one line, indicating the year of Edward‘s query.

Output

For each case, print the number of days of the continuous vacation in that year.

Sample Input
3201520162017
Output
569

題意:給你年份,每年5月1到5月5為固定休息日,但4月30,29有可能是禮拜六天,此時假期加2,5月6,7同理。問你此年份這段時間的長假能是多少
題解:用蔡勒公式判斷這一天是星期幾就好了
#include<map>#include<set>#include<cmath>#include<queue>#include<cstdio>#include<vector>#include<string>#include<cstring>#include<iostream>#include<algorithm>#pragma comment(linker, "/STACK:102400000,102400000")using namespace std;const int N=1010;const int MAX=151;const int MOD=1000000007;const int INF=1000000000;const double EPS=0.00000001;typedef long long ll;int read(){    int x=0,f=1;char ch=getchar();    while(ch<‘0‘||ch>‘9‘){if(ch==‘-‘)f=-1;ch=getchar();}    while(ch>=‘0‘&&ch<=‘9‘){x=x*10+ch-‘0‘;ch=getchar();}    return x*f;}int main(){    int d,c,w,y,m,n,T,ans;    scanf("%d", &T);    while (T--) {        scanf("%d", &n);        ans=5;        y=n%100;c=n/100;        m=4;d=30;        w=((y+y/4+c/4-2*c+26*(m+1)/10+d-1)%7+7)%7;        if (w==0) ans+=2;        else if (w==6) ans++;        m=5;d=6;        w=((y+y/4+c/4-2*c+26*(m+1)/10+d-1)%7+7)%7;        if (w==6) ans+=2;        else if (w==0) ans++;        printf("%d\n", ans);    }    return 0;}
代碼

 



ZOJ 3876 May Day Holiday 蔡勒公式

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.