【HDU】4509 湫湫系列故事——减肥记II (区间覆盖 暴力)

http://acm.hdu.edu.cn/showproblem.php?pid=4509
给出的时间段是被占用的时间,24h = 1440 min,求出这些区间以外的区间长度

把00:00 - 23:59 变成0-1440

1-5都是被占用的区域,暴力很好理解

#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <string>
#include <cstdlib>
#include <map>
typedef long long ll;
using namespace std;

int t[1500];

int main()
{
	int n,sh,sm,eh,em;
	while(scanf("%d",&n)!=EOF)
	{
		if(n<=0)
		{
			break;
		}
		memset(t,0,sizeof(t));
		while(n--)
		{
			scanf("%d:%d %d:%d",&sh,&sm,&eh,&em);
			int t1 = sh*60+sm;
			int t2 = eh*60+em;
			t[t1]++;
			t[t2]--;
		}
		int cnt=0,ans=0;
		for(int i=0;i<1440;i++)
		{
			cnt += t[i];
			if(cnt==0)
				ans++;
		}
		printf("%d\n",ans);
	}
	return 0;
}

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值