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;
    }
  • 相关阅读:
    70 sudo-用来以其他身份来执行命令
    69 su -用户和工作组管理
    68 id -显示用户的id
    71 fdisk-Linux 的磁盘分区表操作工具。
    《刘润·5分钟商学院》学习总结01
    批量创建用户和密码
    20 seq 某个数到另外一个数之间的所有整数
    grub.conf文件参数详解
    dig 常用的域名查询工具
    请问-bash-4.1$ 出现故障的原理及解决办法?
  • 原文地址:https://www.cnblogs.com/shuitiangong/p/12076012.html
Copyright © 2011-2022 走看看