hihocoder1148https://hihocoder.com/problemset/problem/1148
因为题目没有给范围,我本来是这么写的。
for(int i = ; i <= ; i++){
if(i%==&&i%!=||i%==){
cnt++;
}
memo[i] = cnt;
}
然后RE了,事实证明长度还是很大的。
本题的关键在于利用计算闰年的方法巧妙地实现类似以上的计数。
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cstdlib>
#include<string>
#include<cmath>
#include<vector>
#include<stack>
#include<iterator>
#include<queue>
#include<cctype>
#include<map>
#define lson l, m, rt<<1
#define rson m+1, r, rt<<1|1
#define IO ios::sync_with_stdio(false);cin.tie(0);
#define INF 0x3f3f3f3f
#define MAXN 100010
const int MOD=1e9+;
typedef long long ll;
using namespace std;
int n, d1, d2, yy1, y2;
char s1[], s2[];
map<string, int> mp;
int main()
{
cin >> n;
int kase=, cnt=;
mp["January"]=;mp["February"]=;mp["March"]=;
mp["April"]=;mp["May"]=;mp["June"]=;
mp["July"]=;mp["August"]=;mp["September"]=;
mp["October"]=;mp["November"]=;mp["December"]=;
for(int i = ; i < n; i++){
cnt=;
scanf("%s %d, %d", s1, &d1, &yy1);
scanf("%s %d, %d", s2, &d2, &y2);
if(yy1 != y2){
//容斥的感觉
int k1 = yy1/-yy1/+yy1/;
int k2 = (y2-)/-(y2-)/+(y2-)/;
cnt=k2-k1; if(yy1%==&&yy1%!=||yy1%==){
if(mp[s1] <= ){
cnt++;
}
}
if(y2%==&&y2%!=||y2%==){
if(mp[s2] > ||mp[s2]==&&d2==){
cnt++;
}
}
}
else{
if(yy1%==&&yy1%!=||yy1%==){
if((mp[s1] <= )&&(mp[s2]>||mp[s2]==&&d2==))
cnt++;
}
}
cout << "Case #" << ++kase << ": ";
cout << cnt << endl;
}
return ;
}