USACO SEC.1.1 NO.3 Friday the Thirteenth
题意:统计从1900年1月1日(周一)过了n年之后的,每个月13号一共是周几
解法:类似统计给定日期之间间隔几天
/* ID: lsswxr1 PROG: friday LANG: C++ */ #include <iostream> #include <vector> #include <map> #include <list> #include <set> #include <deque> #include <stack> #include <queue> #include <algorithm> #include <cmath> #include <cctype> #include <cstdio> #include <iomanip> #include <cmath> #include <cstdio> #include <string> #include <fstream> #include <string.h> using namespace std; ///宏定义 const int INF = 1000000000; const int MAXN = 1010; const int maxn = MAXN; ///全局变量 和 函数 #define USACO #ifdef USACO #define cin fin #define cout fout #endif ////////////////////////////////////////////////////////////////////////// int n; int Month[2][13] = {0,31,28,31,30,31,30,31,31,30,31,30,31, 0,31,29,31,30,31,30,31,31,30,31,30,31}; int year, month, days; bool isRun(int y) { if ((y % 400 == 0) || ( (y % 100 != 0) && (y % 4 == 0))) return true; return false; } int redays[8]; int week; int main() { #ifdef USACO ofstream fout ("friday.out"); ifstream fin ("friday.in"); #endif ////////////////////////////////////////////////////////////////////////// ///变量定义 while (cin >> n) { memset(redays, 0, sizeof(redays)); year = 1900; month = 1; days = 1; week = 1; int tot = 0; while (n--) { for (month = 1; month <= 12; month++) { int ypos = isRun(year); if (month == 1 && year == 1900) tot += 12; else tot += 13; tot %= 7; redays[tot + 1]++; tot += Month[ypos][month] - 13; } year++; } for (int i = 5; i <= (5 + 6); i++) { int cur = i % 7 + 1; if (cur == 6) cout << redays[cur]; else cout << " " << redays[cur]; } cout << endl; } ///结束 return 0; }