TIANKENG’s restaurant

TIANKENG’s restaurant

Time Limit: 2000/1000 MS (Java/Others)

Memory Limit: 131072/65536 K (Java/Others)
Total Submission(s): 0

Accepted Submission(s): 0

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

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

解题:排序后模拟+优先队列

 1 #include <iostream>
 2 #include <cstdio>
 3 #include <cstring>
 4 #include <cmath>
 5 #include <algorithm>
 6 #include <climits>
 7 #include <vector>
 8 #include <queue>
 9 #include <cstdlib>
10 #include <string>
11 #include <set>
12 #define LL long long
13 #define INF 0x3f3f3f3f
14 using namespace std;
15 struct node {
16     int time,index;
17     friend bool operator< (node x,node b) {
18         return x.time > b.time;
19     }
20 };
21 priority_queue<node>q;
22 struct P {
23     int num,ary,lev;
24 };
25 P p[10020];
26 bool cmp(const P &x,const P &y) {
27     return (x.ary < y.ary || x.ary == y.ary && x.lev < y.lev);
28 }
29 int main() {
30     int t,i,j,n,k;
31     int h1,h2,m1,m2;
32     scanf("%d",&t);
33     while(t--) {
34         while(!q.empty()) q.pop();
35         scanf("%d",&n);
36         for(i = 0; i < n; i++) {
37             scanf("%d %d:%d %d:%d",&k,&h1,&m1,&h2,&m2);
38             p[i].ary = h1*60+m1;
39             p[i].lev = h2*60+m2;
40             p[i].num = k;
41         }
42         sort(p,p+n,cmp);
43         int tm,ans = 0,ba = 0;//剩余的桌子
44         q.push((node) {p[0].lev,0});
45         ans = p[0].num;
46         node tp;
47         for(i = 1; i < n; i++) {
48             tm = p[i].ary;
49             if(p[i].ary == p[i].lev) continue;
50             tp = q.top();
51             q.push((node){p[i].lev,i});
52             while(!q.empty() && tp.time <= tm){
53                 ba += p[tp.index].num;
54                 q.pop();
55                 tp = q.top();
56             }//回收操作
57             if(p[i].num > ba) {
58                 ans += p[i].num-ba;
59                 ba = 0;
60             }else ba -= p[i].num;//分配
61         }
62         printf("%d\n",ans);
63     }
64     return 0;
65 }

TIANKENG’s restaurant,布布扣,bubuko.com

时间: 2024-10-21 19:44:20

TIANKENG’s restaurant的相关文章

BestCoder Round #2 1001 TIANKENG’s restaurant

不得不说,bastcoder是个hack游戏啊!!! 题意:求最少要多少张椅子才能让所有来的客人有地方坐!! 就是一个区间的处理吧!!!和HDU  1556 我待水似流年,流年待我似水神似!!!! 求的是重叠的区间最大,我们只要标记每个区间会有多少人就可以了!!! 然后在从0到1440分统计就OK了!! AC代码如下: #include<iostream> #include<cstdio> #include<cmath> #include<map> #inc

hdu 4883 TIANKENG’s restaurant(暴力)

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4883 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 t

HDU 4883 TIANKENG’s restaurant Bestcoder 2-1(模拟)

TIANKENG's restaurant Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 131072/65536 K (Java/Others) Total Submission(s): 0    Accepted Submission(s): 0 Problem Description TIANKENG manages a restaurant after graduating from ZCMU, and tens of t

HDU 4883 TIANKENG’s restaurant(区间选点)

HDU 4883 TIANKENG's restaurant 题目链接 题意:给定一些时间作为区间,和一个人数,问要安排多少人去看管(一个人只能看管一个人) 思路:普通的区间选点问题,一个区间拆成一个进入点一个出去点,然后排序循环求答案即可 代码: #include <cstdio> #include <cstring> #include <algorithm> using namespace std; const int N = 20005; struct Man {

HDU 4883 Best Coder Round 2 TIANKENG’s restaurant 题解

有一组数据是客人到来和离开的时间,问需要多少张桌椅才能满足所有客人都能有位置坐的要求. 有人居然一开始就想到暴力法,以为数据量少,其实本题数据量不少了, 暴力法需要O(n*n)的时间效率了,显然是会超时的,故此需要O(n) 或者O(lgn)的算法. 属于一道想透了就非常容易的,但是没想过就会非常困难的题目. 解法是: 把所有客人到来和离开的时间都排成序列,每次客人到来需要n张桌椅,那么就+上n,每次客人离开就会返还n张桌椅,那么就-去n,求这样的最大值. 具体算法代码就那么几行,处理IO的代码都

HDU 4883 TIANKENG’s restaurant (贪心)

链接:带我学习,带我飞 第一次BC,稳挂,WA n多次,今天重新做了一下 略挫 #include <iostream> #include <cstdio> #include <cstdlib> #include <cstring> #include <map> #include <string> #include <vector> #include <set> #include <algorithm>

HDU 4886 TIANKENG’s restaurant(Ⅱ)

题意: 一个字符串有许多子串  现要找出最短的字典序最小的不是它的子串的串  这个长串只有A~H字母 思路: YY一下答案串能有多长  8^7就比长串长了  所以也就是7的长度 那么只需要枚举长度  利用哈希判定字符串出现的问题  如何哈希呢? 一共就8个字母明显搞成8进制数  例如  AABCAD 就是 001203(8)  只有7的长度连int都不会爆  哈希稳稳的 而且通过hash值可以很简单的转化回字符串  输出也方便 代码: #include<cstdio> #include<

HDU 4883 TIANKENG’s restaurant (区间更新)

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

hdu4883 TIANKENG’s restaurant 模拟下就好了

TIANKENG's restaurant Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 131072/65536 K (Java/Others) Total Submission(s): 102    Accepted Submission(s): 45 Problem Description TIANKENG manages a restaurant after graduating from ZCMU, and tens o