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;
}
本文介绍了一种算法,用于计算给定多个已占用时间段的情况下,一天内未被占用的时间段总长度。通过将时间转换为分钟数并使用计数数组,可以有效地找出未占用的空闲时间。
1625

被折叠的 条评论
为什么被折叠?



