hdu-4883- (Best Coder) TIANKENG’s restaurant

来源:互联网 发布:淘宝卖假货怎么处罚 编辑:程序博客网 时间:2024/05/18 03:35


TIANKENG’s restaurant

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 131072/65536 K (Java/Others)
Total Submission(s): 1622    Accepted Submission(s): 583


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
 



题目分析:开始自己写的代码一直wa不知道怎么回事,后来听大神讲了一下,好像明白了,就是说如果第一组客人走后这些个椅子可以已给下一波用也可以给下下一波用,

那么我这个代码就出问题了,我这个代码是比较下一个区间和上一个区间是否相交或覆盖。也就是这种情况: 第一波来了6人吃完走了,第二波5人来了,没吃完呢,第三波5人来了。如果是这个代码结果就是  11 了。但是事实上结果应该是 10的。想一想是不是。



<span style="font-size:24px;">#include<cstdio>#include<cstring>#include<algorithm>using namespace std;struct people{    char st[20];//来的时间    char et[20];//走的时间    int sum;}arr[10010];bool cmp(people a,people b){    return strcmp(a.et,b.et)<0;}int main(){    int t,n,i;    scanf("%d",&t);    while(t--)    {        scanf("%d",&n);        for(i=0;i<n;++i)            scanf("%d %s %s",&arr[i].sum,arr[i].st,arr[i].et);//以前写过一道题(hdu-开门人和关门人),这个时间可以用字符串比较,因为是按照一定格式写的,所以以字符串输入没问题        sort(arr,arr+n,cmp);        int cnt=arr[0].sum;                for(i=1;i<n;++i)        {            if(strcmp(arr[i-1].et,arr[i].st)>0)//如果有公共部分            {                cnt+=arr[i].sum;            }            else            {                cnt=arr[i].sum>cnt?arr[i].sum:cnt;            }        }        printf("%d\n",cnt);    }    return 0;}</span>


看这个代码也是暴力模拟解法也没超时,不过我感觉已经很巧妙了

<span style="font-size:24px;">#include<cstdio>#include<cstring>#include<iostream>using namespace std;#define maxn 25000int time[maxn];int main(){int n;scanf("%d",&n);while(n--){int num,h1,t1,h2,t2,T;scanf("%d",&T);memset(time,0,sizeof(time));while(T--){     scanf("%d %d:%d %d:%d",&num,&h1,&t1,&h2,&t2);    int hour1=h1*60+t1;    int hour2=h2*60+t2;    time[hour1]+=num;    time[hour2]-=num;} int i,sum=0;for(i=1;i<=1440;i++){     time[i]+=time[i-1];//这里必须是当前数量加上上一个时间点的数量,不理解的话可以拿上面说的   6 5 5 这个数据模拟一遍    sum=max(sum,time[i]);//这里sum 要始终存最大值,自己模拟一下我说的这组数据就很好理解了}   printf("%d\n",sum);}return 0; }</span> 






















0 0