TIANKENG’s restaurant
Time Limit:1000MS Memory Limit:65536KB 64bit IO Format:%I64d & %I64u
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
题目大意:这道题实质上就是找是否有重叠的时间区间,如果有重叠部分,则对应的两波人人数相加,否则取其中最大的人数。
解题思路:本来想对来的时间和走的时间分别排序,再两者看是否有重叠部分,但这样想无疑是异想天开。。水平达不到啊!参考了别人的题解后,知道了可以把时间转化成具体的数字(<24*60),这样就可以用打表把对应时间区间所对应的数字区间全部用该组人数标记,有重叠的就相加,最后排序,取最大值就行了!
#include<stdio.h>
#include<string.h>
#include<algorithm>
using namespace std;
int b[24*60+1];
struct node {
int x; //来的人数
int arrive; //来的时间所对应的数值
int leave; //走的时间所对应的数值
}a[10100];
bool cmp(int x,int y){
return x>y;
}
int main(){
int t,n;
int h1,m1,h2,m2;
scanf("%d",&t);
while(t--){
scanf("%d",&n);
memset(b,0,sizeof(b));
for(int i=0;i<n;i++){
scanf("%d %d:%d %d:%d",&a[i].x,&h1,&m1,&h2,&m2);
a[i].arrive=h1*60+m1;
a[i].leave=h2*60+m2; //时间转化
for(int j=a[i].arrive;j<a[i].leave;j++)
b[j]+=a[i].x;//区间打表
}
sort(b,b+24*60+1,cmp); //从大到小排列
printf("%d\n",b[0]); //输出最大值
}
return 0;
}