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 ;
}

hihocoder1148 February 29(区间闰年计数)的更多相关文章

  1. LightOJ 1414 February 29(闰年统计+容斥原理)

    题目链接:https://vjudge.net/contest/28079#problem/R 题目大意:给你分别给你两个日期(第二个日期大于等于第一个日期),闰年的2月29日称为闰日,让你求两个日期 ...

  2. February 29(模拟)

    D - D Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%lld & %llu Submit Status P ...

  3. $CH5302$ 金字塔 区间$DP$/计数类$DP$

    CH Sol f[l][r]表示l到r这段区间对应的金字塔结构种数 发现是f[l][r]是可以由比它小的区间推出来的 比如已知f[l+1][k],f[k+1][r],不难想到f[l][r]+=f[l+ ...

  4. [LeetCode] Count of Range Sum 区间和计数

    Given an integer array nums, return the number of range sums that lie in [lower, upper] inclusive.Ra ...

  5. Bipartite Segments CodeForces - 901C (区间二分图计数)

    大意: 给定无向图, 无偶环, 每次询问求[l,r]区间内, 有多少子区间是二分图. 无偶环等价于奇环仙人掌森林, 可以直接tarjan求出所有环, 然后就可以预处理出每个点为右端点时的答案. 这样的 ...

  6. [LeetCode] 327. Count of Range Sum 区间和计数

    Given an integer array nums, return the number of range sums that lie in [lower, upper] inclusive.Ra ...

  7. 327 Count of Range Sum 区间和计数

    Given an integer array nums, return the number of range sums that lie in [lower, upper] inclusive.Ra ...

  8. Hihocoder 2月29日

      时间限制:2000ms 单点时限:1000ms 内存限制:256MB 描述 给定两个日期,计算这两个日期之间有多少个2月29日(包括起始日期). 只有闰年有2月29日,满足以下一个条件的年份为闰年 ...

  9. hihoCoder 1148 2月29日

    时间限制:2000ms 单点时限:1000ms 内存限制:256MB 描述 给定两个日期,计算这两个日期之间有多少个2月29日(包括起始日期). 只有闰年有2月29日,满足以下一个条件的年份为闰年: ...

随机推荐

  1. 前端本地存储localStorage

    1.突破cookie 4K限制,一般浏览器支持5M 2.增 删 改 查 <!DOCTYPE html> <html lang="en"> <head& ...

  2. css3实现旋转表

    如图所示: css部分: <style> #clock{width:100px; height:100px; border-radius:50%; border:4px solid bla ...

  3. AtCoder Grand Contest 002 (AGC002) F - Leftmost Ball 动态规划 排列组合

    原文链接https://www.cnblogs.com/zhouzhendong/p/AGC002F.html 题目传送门 - AGC002F 题意 给定 $n,k$ ,表示有 $n\times k$ ...

  4. 2018牛客网暑假ACM多校训练赛(第三场)I Expected Size of Random Convex Hull 计算几何,凸包,其他

    原文链接https://www.cnblogs.com/zhouzhendong/p/NowCoder-2018-Summer-Round3-I.html 题目传送门 - 2018牛客多校赛第三场 I ...

  5. BZOJ1856 [Scoi2010]字符串 数论

    原文链接http://www.cnblogs.com/zhouzhendong/p/8084577.html 题目传送门 - BZOJ1856 题意概括 找出由n个1,m个0组成的字符串,且任意前几个 ...

  6. Python replace() 和 re.sub() 字符串字符替换

    Python replace() 和 re.sub() 字符串字符替换 replace() testStr = 'aa:bb[cc' testStr.replace(':','_') 每次只能替换一个 ...

  7. 用sql的avg(score)求完平均值后,保存两位小数的方法(用于查询或视图)

    查jx_score表的平均值,以哪次考试(testid)和科目分组(courseid) select testid, courseid, round(avg(`jx_score`.`score`),2 ...

  8. Ultra-QuickSort POJ - 2299 (逆序对)

    In this problem, you have to analyze a particular sorting algorithm. The algorithm processes a seque ...

  9. RedisCacheManager设置Value序列化器技巧

    CacheManager基本配置 请参考博文:springboot2.0 redis EnableCaching的配置和使用 RedisCacheManager构造函数 /** * Construct ...

  10. SpringMVC之搭建框

    1. 创建Web工程 2. 修改环境配置 2.1 背景:因为创建的web工程,classe文件默认保存在build/classes里,而WEB-INF下的文件无法通过外部访问,更加安全,所以修改cla ...