【CUGBACM15级BC第二场 A】hdu 4883 TIANKENG’s restaurant

来源:互联网 发布:上海金慧软件 编辑:程序博客网 时间:2024/06/08 16:48

TIANKENG’s restaurant

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


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
 

题目大意:一间餐厅,给你每组客人的人数和来的时间,离开的时间,问最少需要的椅子。


解题思路:这题本来想用区间覆盖做,可是后面发觉不太对。这题貌似暴力也是可以过的,因为时间才1440.其中的一种做法:把每个区间的开始和结束时间点都标记上是来人还是走人,对应的椅子数加上减去。然后在枚举一下时间,在这个过程中维护椅子的最大值。也可以把出入的时间点记录下来,因为这些时间点人数是在变化的,然后也是维护最大值,但是要记得重复的时间点不要加多次

#include <iostream>#include <set>#include <map>#include <stack>#include <cmath>#include <queue>#include <cstdio>#include <bitset>#include <string>#include <vector>#include <iomanip>#include <cstring>#include <algorithm>#include <functional>#define PI acos(-1)#define eps 1e-8#define inf 0x3f3f3f3f#define debug(x) cout<<"---"<<x<<"---"<<endltypedef long long ll;using namespace std;int a[1600];int main(){    int t;    cin >> t;    while (t--)    {        memset(a, 0, sizeof(a));        int n;        cin >> n;        int x, h1, h2, m1, m2;        for (int i = 0; i < n; i++)        {            scanf("%d%d:%d%d:%d", &x, &h1, &m1, &h2, &m2);            int start = 60 * h1 + m1;            int endd = 60 * h2 + m2;            for (int k = start; k < endd; k++)            {                a[k] += x;            }        }        int ans = 0;        for (int i = 0; i < 1600; i++)        {            ans = max(ans, a[i]);        }        cout << ans << endl;    }    return 0;}


阅读全文
0 0
原创粉丝点击