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日,满足以下一个条件的年份为闰年: ...
随机推荐
- Python_迭代器
迭代器:迭代器里的元素读一个丢一个,不能回退,不能用下标访问 x.__next__():迭代器里唯一的方法,只读下一个 d = iter(['Presly', 'is', 'lovely', ]) p ...
- Python知识回顾 —— 面向对象
博客转载自 http://www.cnblogs.com/wupeiqi/p/4766801.html http://www.cnblogs.com/linhaifeng/articles/62040 ...
- 移动端1px问题
.component-confirm__buttons { border-top: 1px solid #eceef0; box-shadow: 0 1px 1px #fff; } 造成边框变粗的原因 ...
- BZOJ2287 【POJ Challenge】消失之物 动态规划 分治
原文链接http://www.cnblogs.com/zhouzhendong/p/8684027.html 题目传送门 - BZOJ2287 题意 有$n$个物品,第$i$个物品的体积为$w_i$. ...
- Period kmp
For each prefix of a given string S with N characters (each character has an ASCII code between 97 a ...
- Python Enum 枚举 用法汇总
Python Enum 枚举 用法汇总 import os import sys if sys.version_info.major + sys.version_info.minor * 0.1 &l ...
- springboot配置log4j
maven 配置jar包 <dependency> <groupId>org.springframework.boot</groupId> <artifact ...
- Knn:Knn实现对150朵共三种花的实例的萼片长度、宽,花瓣长、宽数据统计,根据一朵新花的四个特征来预测其种类
from sklearn import neighbors from sklearn import datasets knn = neighbors.KNeighborsClassifier() ir ...
- 【LeetCode算法-9】Palindrome Number
LeetCode第9题 Determine whether an integer is a palindrome. An integer is a palindrome when it reads t ...
- Python并发复习2 - 多线程模块threading
一.多线程的调用 threading 模块建立在thread 模块之上.thread模块以低级.原始的方式来处理和控制线程,而threading 模块通过对thread进行二次封装, 提供了更方便的a ...