zoukankan      html  css  js  c++  java
  • zzulioj 2600: 有多少天?

    题目链接:http://acm.zzuli.edu.cn/problem.php?id=2600

      模拟,既然1900 01 01是周一,那就从这一天开始加,直到加到满足题目条件的区间里再去做判断

    #include<set>
    #include<map>
    #include<stack>
    #include<queue>
    #include<cmath>
    #include<cstdio>
    #include<cctype>
    #include<string>
    #include<vector>
    #include<climits>
    #include<cstring>
    #include<cstdlib>
    #include<iostream>
    #include<algorithm>
    #define max(a, b) (a > b ? a : b)
    #define min(a, b) (a < b ? a : b)
    #define mst(a) memset(a, 0, sizeof(a))
    #define _test printf("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n")
    using namespace std;
    typedef long long ll;
    typedef pair<int, int> P;
    const double eps = 1e-7;
    const int INF = 0x3f3f3f3f;
    const ll ll_INF = 0x3f3f3f3f3f3f3f;
    const int maxn = 1e4+10;
    const int ls[13] = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
    bool isr(int y) { //判断闰年
        return (y%100 && !(y%4)) || !(y%400); 
    }
    bool ok(int sum, int w) { //判断是不是周w
        return sum%7 + 1 == w;
    }
    int main(void) {
        int x, y, z, w;
        while(~scanf("%d%d%d%d", &x, &y, &z, &w)) {
            ll sum = z-1; 
            int start = 1900;
            while(start < x) { //计算x年1月z号到1900年1月1号的天数
                sum += (365 + isr(start));
                ++start;
            }
            int cnt = 0;
            while(start <= y) { //求解答案
                for (int i = 1; i<=12; ++i) {
                    sum += ls[i-1]; //加上上个月的天数
                    if (i == 3) //如果要加上2月的天数, 判断要不要补1
                        sum += isr(start);
                    if ((i==2 && z > ls[2]+isr(start)) || (i != 2 && z > ls[i])) //如果该月的z号不存在,跳过, 不统计次数
                        continue;
                    cnt += ok(sum, w); //统计次数
                }
                sum += ls[12]; //加上第十二月的天数
                ++start; //换到下一年
            }
            printf("%d\n", cnt);
        }
        return 0;
    }
  • 相关阅读:
    Java LinkedList 源码剖析
    Java并发编程:线程池的使用
    Java 线程池的原理与实现
    多线程JAVA篇(一)
    软件开发中会用到的图
    linux文件名匹配——通配符使用
    XModem协议
    dmesg 命令七种用法
    定位精度单位CEP、RMS、2DRMS常识
    5G NR 技术简介
  • 原文地址:https://www.cnblogs.com/shuitiangong/p/12076012.html
Copyright © 2011-2022 走看看