hihocoder1148 February 29(区间闰年计数)
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(区间闰年计数)的更多相关文章
- LightOJ 1414 February 29(闰年统计+容斥原理)
题目链接:https://vjudge.net/contest/28079#problem/R 题目大意:给你分别给你两个日期(第二个日期大于等于第一个日期),闰年的2月29日称为闰日,让你求两个日期 ...
- February 29(模拟)
D - D Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%lld & %llu Submit Status P ...
- $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+ ...
- [LeetCode] Count of Range Sum 区间和计数
Given an integer array nums, return the number of range sums that lie in [lower, upper] inclusive.Ra ...
- Bipartite Segments CodeForces - 901C (区间二分图计数)
大意: 给定无向图, 无偶环, 每次询问求[l,r]区间内, 有多少子区间是二分图. 无偶环等价于奇环仙人掌森林, 可以直接tarjan求出所有环, 然后就可以预处理出每个点为右端点时的答案. 这样的 ...
- [LeetCode] 327. Count of Range Sum 区间和计数
Given an integer array nums, return the number of range sums that lie in [lower, upper] inclusive.Ra ...
- 327 Count of Range Sum 区间和计数
Given an integer array nums, return the number of range sums that lie in [lower, upper] inclusive.Ra ...
- Hihocoder 2月29日
时间限制:2000ms 单点时限:1000ms 内存限制:256MB 描述 给定两个日期,计算这两个日期之间有多少个2月29日(包括起始日期). 只有闰年有2月29日,满足以下一个条件的年份为闰年 ...
- hihoCoder 1148 2月29日
时间限制:2000ms 单点时限:1000ms 内存限制:256MB 描述 给定两个日期,计算这两个日期之间有多少个2月29日(包括起始日期). 只有闰年有2月29日,满足以下一个条件的年份为闰年: ...
随机推荐
- EntityFramework 优化建议(转)
转载地址:http://blog.jd-in.com/947.html Entity Framework目前最新版本是6.1.3,当然Entity Framework 7 目前还是预览版,并不能投入正 ...
- 【BZOJ2560】串珠子
题解: 跟n个点有标号的无向连通图个数几乎一模一样 直接上代码了 代码: #include <bits/stdc++.h> using namespace std; #define ll ...
- awk常见用法
awk作为linux字符搜索,结果统计的实用工具,其在linux日常运维中有着很多的巧妙运用.下面就来技术一下刚刚学到的技巧 #awk命令统计文件夹下所有文件大小 ls -l |awk 'BEGIN ...
- 如何使用maven进行avro序列化
maven导入avro: <dependency> <groupId>org.apache.avro</groupId> <artifactId>avr ...
- $on在构造器外部添加事件$once执行一次的事件$off关闭事件
$on 在构造器外部添加事件. $on接收两个参数,第一个参数是调用时的事件名称,第二个参数是一个匿名方法. 如果按钮在作用域外部,可以利用$emit来执行. html <div id=&quo ...
- BZOJ2287 【POJ Challenge】消失之物 动态规划 分治
原文链接http://www.cnblogs.com/zhouzhendong/p/8684027.html 题目传送门 - BZOJ2287 题意 有$n$个物品,第$i$个物品的体积为$w_i$. ...
- Redis Pubsub命令用法
一.什么是pub/sub及实现Pub/Sub功能(means Publish, Subscribe)即发布及订阅功能. Redis通过publish和subscribe命令实现订阅和发布的功能. 订阅 ...
- P1156 垃圾陷阱 DP
题目描述 卡门――农夫约翰极其珍视的一条Holsteins奶牛――已经落了到“垃圾井”中.“垃圾井”是农夫们扔垃圾的地方,它的深度为D(2 \le D \le 100)D(2≤D≤100)英尺. 卡门 ...
- sql语句表示不等于
<> != 后面均不带引号“”
- python urllib 库
urllib模块中的方法 1.urllib.urlopen(url[,data[,proxies]]) 打开一个url的方法,返回一个文件对象,然后可以进行类似文件对象的操作.本例试着打开google ...