zoukankan      html  css  js  c++  java
  • 水题 ZOJ 3876 May Day Holiday

    题目传送门

     1 /*
     2     水题:已知1928年1月1日是星期日,若是闰年加1,总天数对7取余判断就好了;
     3 */
     4 #include <cstdio>
     5 #include <iostream>
     6 #include <algorithm>
     7 #include <cmath>
     8 #include <cstring>
     9 #include <string>
    10 #include <map>
    11 #include <set>
    12 #include <queue>
    13 #include <vector>
    14 using namespace std;
    15 
    16 const int MAXN = 1e4 + 10;
    17 const int INF = 0x3f3f3f3f;
    18 int cnt[MAXN];
    19 
    20 void leap(void)
    21 {
    22     memset (cnt, 0, sizeof (cnt));
    23 
    24     for (int i=1900; i<=10000; ++i)
    25     {
    26         if ((i % 4 == 0 && i % 100 != 0) || i % 400 == 0)
    27             cnt[i] = 1;
    28     }
    29 }
    30 
    31 int main(void)      //ZOJ 3876 May Day Holiday
    32 {
    33     //freopen ("H.in", "r", stdin);
    34 
    35     int t;
    36 
    37     leap ();
    38     scanf ("%d", &t);
    39     while (t--)
    40     {
    41         int year, day;
    42         scanf ("%d", &year);
    43 
    44         day = (year - 1928) * 365;
    45         for (int i=1928; i<=year; ++i)
    46             day += cnt[i];
    47         day += (31 + 28 + 31 + 30);
    48 
    49         int ans = day % 7;
    50         if(ans == 2) printf("6
    ");
    51         else if(ans == 4|| ans == 5 || ans == 3 || ans == 6) printf("5
    ");
    52         else if(ans == 1) printf("9
    ");
    53         else if(ans == 0) printf("6
    ");
    54     }
    55 
    56 
    57     return 0;
    58 }
    编译人生,运行世界!
  • 相关阅读:
    GIL锁、进程池和线程池、同步和异步
    线程
    socket编程
    单例模式
    反射、自定义内置方法来定制类的功能、元类
    elasticSearch(一)--数据1
    docker学习整理(三)
    docker学习整理(二)
    docker学习整理(一)
    IDEA 配置mybatis生成代码
  • 原文地址:https://www.cnblogs.com/Running-Time/p/4457859.html
Copyright © 2011-2022 走看看