zoukankan      html  css  js  c++  java
  • ZOJ 3876 May Day Holiday 蔡勒公式

                                                   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

    3
    2015
    2016
    2017
    

    Output

    5
    6
    9

    题意:给你年份,每年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
    ", ans);
        }
        return 0;
    }
    代码


  • 相关阅读:
    学习进度第七周
    NABCD---生活日历
    学习进度第六周
    人月神话阅读笔记(3)
    人月神话阅读笔记(2)
    人月神话阅读笔记(1)
    石家庄地铁查询(双人项目)
    学习进度第五周
    学习进度第四周
    返回一个整数数组中最大子数组的和。(续2)---二维数组
  • 原文地址:https://www.cnblogs.com/zxhl/p/4865525.html
Copyright © 2011-2022 走看看