Kattis - friday 【数学】

mac2022-06-30  22

题意 每一年的第一天 都是星期天 然后 给出 一年的总天数 和 总月数 以及 每个月 的总天数 求出 有多少个星期五 是当月的13号

思路 对于 每个月 只要判断 当月的13号 是不是 星期五 就可以了 那么 给出 一个 第几天 怎么判断 是星期几呢

因为 每年的第一天 都是星期天 所以 我们可以 依次 另 星期天 到 星期六 为 0-6 然后 给出第几天(tot) 我们 只要 用(tot - 1) % 7 来判断 就可以了

AC代码

#include <cstdio> #include <cstring> #include <ctype.h> #include <cstdlib> #include <climits> #include <iostream> #include <algorithm> #include <cmath> #include <deque> #include <vector> #include <queue> #include <string> #include <map> #include <stack> #include <set> #include <numeric> #include <sstream> #include <iomanip> #include <limits> using namespace std; typedef long long ll; typedef long double ld; typedef pair <int, int> pii; typedef pair <ll, ll> pll; const double PI = 3.14159265358979323846264338327; const double E = exp(1); const double eps = 1e-6; const int INF = 0x3f3f3f3f; const int maxn = 1e3 + 5; const int MOD = 1e9 + 7; int main() { int t; cin >> t; while (t--) { int d, m; scanf("%d%d", &d, &m); int ans = 0; int tot = 0; for (int i = 0; i < m; i++) { scanf("%d", &d); if ((tot + 12) % 7 == 5 && d >= 13) ans++; tot += d; } cout << ans << endl; } }

转载于:https://www.cnblogs.com/Dup4/p/9433245.html

最新回复(0)