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

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

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

【HDU】4509 湫湫系列故事——减肥记II (区间覆盖 暴力)_第1张图片

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

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

 

你可能感兴趣的:(HDU)