【HDU 4883】TIANKENG’s restaurant(区间更新)

来源:互联网 发布:ug软件下载 编辑:程序博客网 时间:2024/05/01 18:27

Description

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?

Input

The first line contains a positive integer T(T<=100), standing for T test cases in all.

Each 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.

Output

For each test case, output the minimum number of chair that TIANKENG needs to prepare.

Sample Input

2
2
6 08:00 09:00
5 08:59 09:59
2
6 08:00 09:00
5 09:00 10:00

Sample Output

11
6

题目大意

有n个旅行团去餐厅吃饭,每个旅行团有x个人,并且他们到达店铺的时间和离店时间已知,求至少需要几张椅子可以让每一个旅行团到达时都有椅子坐。

思路

题目不难,以时间为单位不断去更新区间,如果有旅行团在s时刻到了店铺,就将需要的椅子总数sum[s]+=temp,temp表示这个旅行团的人数,如果某个旅行团在e时间离开了饭店,那么就将椅子总数sum[e]-=temp,那么我任意一个时刻time需要的椅子数就是当前时刻的椅子数sum[time]+sum[time-1],最后跑一遍循环找到最大一个sum输出即可。

代码

#include <iostream>#include <cstdio>#include <cstring>#include <algorithm>using namespace std;const int maxn=1500;int sum[maxn],t,n;int main(){    scanf("%d",&t);    while(t--)    {        scanf("%d",&n);        memset(sum,0,sizeof(sum));        for(int i=0;i<n;i++)        {            int temp,h1,h2,m1,m2;            scanf("%d %d:%d %d:%d",&temp,&h1,&m1,&h2,&m2);            int sta=h1*60+m1;            int end=h2*60+m2;            sum[sta]+=temp;            sum[end]-=temp;        }        int ans=sum[0];        for(int i=1;i<=1440;i++)        {            sum[i]+=sum[i-1];            ans=max(ans,sum[i]);        }        printf("%d\n",ans);    }    return 0;}
0 0