水题 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\n"); 51 else if(ans == 4|| ans == 5 || ans == 3 || ans == 6) printf("5\n"); 52 else if(ans == 1) printf("9\n"); 53 else if(ans == 0) printf("6\n"); 54  } 55 56 57 return 0; 58 }

 

你可能感兴趣的:(ZOJ)