【模拟】HDU4509湫湫系列故事——减肥记II
2016-04-16 12:02
197 查看
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4509
Problem Description
虽然制定了减肥食谱,但是湫湫显然克制不住吃货的本能,根本没有按照食谱行动!
于是,结果显而易见…
但是没有什么能难倒高智商美女湫湫的,她决定另寻对策——吃没关系,咱吃进去再运动运动消耗掉不就好了?
湫湫在内心咆哮:“我真是天才啊~\(≧▽≦)/~”
可是,大家要知道,过年回家多忙啊——帮忙家里做大扫除,看电影,看小说,高中同学聚餐,初中同学聚餐,小学同学聚餐,吃东西,睡觉,吃东西,睡觉,吃东西,睡觉……所以锻炼得抽着时间来。
但是,湫湫实在太忙了,所以没时间去算一天有多少时间可以用于锻炼,现在她把每日行程告诉你,拜托你帮忙算算吧~
皮埃斯:一天是24小时,每小时60分钟
Input
输入数据包括多组测试用例。
每组测试数据首先是一个整数n,表示当天有n件事要做。
接下来n行,第i行是第i件事的开始时间和结束时间,时间格式为HH:MM。
[Technical Specification]
1. 1 <= n <= 500000
2. 00 <= HH <= 23
3. 00 <= MM <= 59
Output
请输出一个整数,即湫湫当天可以用于锻炼的时间(单位分钟)
Sample Input
1
15:36 18:40
4
01:35 10:36
04:54 22:36
10:18 18:40
11:47 17:53
Sample Output
1256
179
Hint
大量输入,建议用scanf读数据。
代码1:这是我自己模拟的思路做的;
#include<iostream>
#include<cstring>
#include<cstdio>
#include<algorithm>
using namespace std;
struct node
{
int s,e;
}stu[500005];
bool cmp(node a,node b)
{
if(a.s!=b.s) return a.s<b.s;
else return a.e<b.e;
}
int main()
{
int n;
while(~scanf("%d",&n)){
int time=0;
for(int i=0;i<n;i++){
int h1,h2,m1,m2;
scanf("%d:%d %d:%d",&h1,&m1,&h2,&m2);
stu[i].s=h1*60+m1;
stu[i].e=h2*60+m2;
}
sort(stu,stu+n,cmp);
int flag=1;
for(int i=1;i<n;i++){
if(stu[i].s<stu[i-1].e){
stu[i].s=stu[i-1].s;
stu[i].e=max(stu[i].e,stu[i-1].e);
}else{
time+=stu[i-1].e-stu[i-1].s;
}
}
time+=stu[n-1].e-stu[n-1].s;
printf("%d\n",60*24-time);
}
return 0;
}
代码2:这是我在Discuss了看到的别人的代码,思维真的很重要!!
#include<iostream>
#include<cstring>
#include<algorithm>
#include<cstdio>
using namespace std;
int main()
{
int n;
while(~scanf("%d",&n)){
int time[1448];
memset(time,1,sizeof(time));
for(int i=0;i<n;i++){
int h1,h2,m1,m2;
scanf("%d:%d %d:%d",&h1,&m1,&h2,&m2);
int s=h1*60+m1;
int e=h2*60+m2;
memset(time+s,0,(e-s)*sizeof(int));
}
int cnt=0;
for(int i=0;i<24*60;i++){
if(time[i]) cnt++;
}
printf("%d\n",cnt);
}
return 0;
}
Problem Description
虽然制定了减肥食谱,但是湫湫显然克制不住吃货的本能,根本没有按照食谱行动!
于是,结果显而易见…
但是没有什么能难倒高智商美女湫湫的,她决定另寻对策——吃没关系,咱吃进去再运动运动消耗掉不就好了?
湫湫在内心咆哮:“我真是天才啊~\(≧▽≦)/~”
可是,大家要知道,过年回家多忙啊——帮忙家里做大扫除,看电影,看小说,高中同学聚餐,初中同学聚餐,小学同学聚餐,吃东西,睡觉,吃东西,睡觉,吃东西,睡觉……所以锻炼得抽着时间来。
但是,湫湫实在太忙了,所以没时间去算一天有多少时间可以用于锻炼,现在她把每日行程告诉你,拜托你帮忙算算吧~
皮埃斯:一天是24小时,每小时60分钟
Input
输入数据包括多组测试用例。
每组测试数据首先是一个整数n,表示当天有n件事要做。
接下来n行,第i行是第i件事的开始时间和结束时间,时间格式为HH:MM。
[Technical Specification]
1. 1 <= n <= 500000
2. 00 <= HH <= 23
3. 00 <= MM <= 59
Output
请输出一个整数,即湫湫当天可以用于锻炼的时间(单位分钟)
Sample Input
1
15:36 18:40
4
01:35 10:36
04:54 22:36
10:18 18:40
11:47 17:53
Sample Output
1256
179
Hint
大量输入,建议用scanf读数据。
代码1:这是我自己模拟的思路做的;
#include<iostream>
#include<cstring>
#include<cstdio>
#include<algorithm>
using namespace std;
struct node
{
int s,e;
}stu[500005];
bool cmp(node a,node b)
{
if(a.s!=b.s) return a.s<b.s;
else return a.e<b.e;
}
int main()
{
int n;
while(~scanf("%d",&n)){
int time=0;
for(int i=0;i<n;i++){
int h1,h2,m1,m2;
scanf("%d:%d %d:%d",&h1,&m1,&h2,&m2);
stu[i].s=h1*60+m1;
stu[i].e=h2*60+m2;
}
sort(stu,stu+n,cmp);
int flag=1;
for(int i=1;i<n;i++){
if(stu[i].s<stu[i-1].e){
stu[i].s=stu[i-1].s;
stu[i].e=max(stu[i].e,stu[i-1].e);
}else{
time+=stu[i-1].e-stu[i-1].s;
}
}
time+=stu[n-1].e-stu[n-1].s;
printf("%d\n",60*24-time);
}
return 0;
}
代码2:这是我在Discuss了看到的别人的代码,思维真的很重要!!
#include<iostream>
#include<cstring>
#include<algorithm>
#include<cstdio>
using namespace std;
int main()
{
int n;
while(~scanf("%d",&n)){
int time[1448];
memset(time,1,sizeof(time));
for(int i=0;i<n;i++){
int h1,h2,m1,m2;
scanf("%d:%d %d:%d",&h1,&m1,&h2,&m2);
int s=h1*60+m1;
int e=h2*60+m2;
memset(time+s,0,(e-s)*sizeof(int));
}
int cnt=0;
for(int i=0;i<24*60;i++){
if(time[i]) cnt++;
}
printf("%d\n",cnt);
}
return 0;
}
相关文章推荐
- Windows Docker的有趣事实 推荐
- Linux用户管理:addgroup、adduser、usermod
- android 调用远程service时报java.lang.SecurityException: Binder invocation to an incorrect interface异常
- position、opacity与z-index的组合
- 复利计算再升级
- 关于stm32定时器的理解
- SeimiAgent——基于QtWebkit的通用网页渲染代理服务
- 关于stm32定时器的理解
- Android 学习记录-零散知识点
- 11. Container With Most Water
- jQuery实现漂亮实用的商品图片tips提示框效果(无图片箭头+阴影)
- 什么是P问题、NP问题和NPC问题
- spring mvc中的@PathVariable
- CentOS安装软件<一> MYSQL
- c++(1)
- 单例模式的五种写法
- 织梦后台jpeg格式图片没法上传,图片浏览器中没法查看预览
- OpenStack 安装教程(使用Fuel )
- lcs nlogn 算法
- HDU 2071