hdu TIANKENG’s restaurant

来源:互联网 发布:wwe2k15优化补丁 编辑:程序博客网 时间:2024/06/11 17:47

Problem 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
226 08:00 09:005 08:59 09:5926 08:00 09:005 09:00 10:00
Sample Output
116
 
--------------------------------------------------------------
思路:就是以开始的时间和结尾的时间为下标,开一个很大的数组,将每次的人数加到数组中,最后查询数组中的最大值,这个最大值就是所需的最少的椅子;
每组的人在餐馆的时间必定有重叠,而这时就要多拿一些板凳;在某个时间段重叠的人数的最大值就是需要的最少的椅子数;
#include<stdio.h>#include<string.h>int main(){ int t,n,sta,end,mx,max,per; int h1,h2,t1,t2,i,j; int a[100000]; memset(a,0,sizeof(a)); scanf("%d",&t); while(t--) {  scanf("%d",&n);  mx = 0;  for(i=0;i<n;i++)  {   scanf("%d %d:%d %d:%d",&per,&h1,&t1,&h2,&t2);   sta = h1*60 + t1;   end = h2*60 + t2;   if(mx<end)    mx = end;   for(j=sta;j<end;j++)//注意这里j不能等于end;    a[j]+=per;  }  max=0;  for(i=0;i<=mx;i++)  {   if(max<a[i])    max = a[i];  }  printf("%d\n",max);  memset(a,0,sizeof(a)); } //while(1); return 0;}
0 0
原创粉丝点击