TIANKENG manages a restaurant after graduating from ZCMU, and tens of thousands of customers come to have meal because of its delicious dishes. Today n groups of customers come to enjoy their meal, and there are Xi persons in the ith group in sum. Assuming that each customer can own only one chair. Now we know the arriving time STi and departure time EDi of each group. Could you help TIANKENG calculate the minimum chairs he needs to prepare so that every customer can take a seat when arriving the restaurant?
InputEach cases has a positive integer n(1<=n<=10000), which means n groups of customer. Then following n lines, each line there is a positive integer Xi(1<=Xi<=100), referring to the sum of the number of the ith group people, and the arriving time STi and departure time Edi(the time format is hh:mm, 0<=hh<24, 0<=mm<60), Given that the arriving time must be earlier than the departure time.
Pay attention that when a group of people arrive at the restaurant as soon as a group of people leaves from the restaurant, then the arriving group can be arranged to take their seats if the seats are enough.
2 2 6 08:00 09:00 5 08:59 09:59 2 6 08:00 09:00 5 09:00 10:00
11 6
思路:和前几篇博文这是一类题,都是在区间上做文章;
如果按照前几篇的思路:一分钟一分钟的处理会超时;但是把握时间 24 * 60 ,在这个区间内循环,并在输入时在各自的区间内将 m 值赋好,这是一类题;
//本题容易超时
#include<stdio.h>
#include<iostream>
#include<math.h>
#include<string.h>
#include<algorithm>
using namespace std;
int a[1500];
int main()
{
int t;
scanf("%d",&t);
while(t--)
{
int maxn=-1,n,m,i,j;
memset(a,0,sizeof(a));
scanf("%d",&n);
int h1,h2,m1,m2,len,len1;
for(i=0;i<n;i++)
{
scanf("%d %d:%d %d:%d",&m,&h1,&m1,&h2,&m2);
len=h1*60+m1,len1=h2*60+m2;//化成具体的分钟,便于后续的循环;
for(j=len;j<len1;j++)
{
a[j]+=m;
}
}
for(i=0;i<1450;i++)
{
maxn=max(maxn,a[i]);
}
printf("%d\n",maxn);
}
return 0;
}