HDOJ 4883 TIANKENG’s restaurant(思维)

来源:互联网 发布:php unset函数 编辑:程序博客网 时间:2024/04/30 22:55

TIANKENG’s restaurant

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


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
 

Source
BestCoder Round #2
 

Recommend
liuyiding   |   We have carefully selected several similar problems for you:  5733 5732 5731 5730 5729 

思路:
这个题目起初是用的结构体排序折腾很久,最后看题解换一种思路,就是转换为分钟的数组,然后记录就行了。

代码:
#include<stdio.h>#include<stdlib.h>#include<math.h>#include<string.h>#include<algorithm>#define MYDD 10103using namespace std;bool cmp(int x,int y) {    return x>y;}int MAX(int x,int y) {    return x>y? x:y;}int main() {    int t,n;    int liu,ch,cm,lh,lm;    int ans[24*60+4];//用于记录当前分钟的人数    scanf("%d",&t);    while(t--) {        memset(ans,0,sizeof(ans));        scanf("%d",&n);        while(n--) {            scanf("%d %d:%d %d:%d",&liu,&ch,&cm,&lh,&lm);            int come=ch*60+cm;//一小时60分钟,自己弄成24,也是够了             int left=lh*60+lm-1;//防止时间的重复            for(int j=come; j<=left; j++) {                ans[j]+=liu;            //    printf("****%d*****%d\n",j,ans[j]);            }        }        sort(ans,ans+24*60+4,cmp);        printf("%d\n",ans[0]);    }    return 0;}


0 0