TIANKENG’s restaurant 【区间覆盖 好题】
2016-07-22 21:28
351 查看
TIANKENG’s restaurant
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 131072/65536 K (Java/Others)Total Submission(s): 2556 Accepted Submission(s): 950
[align=left]Problem Description[/align]
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?
[align=left]Input[/align]
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.
[align=left]Output[/align]
For each test case, output the minimum number of chair that TIANKENG needs to prepare.
[align=left]Sample Input[/align]
2
2
6 08:00 09:00
5 08:59 09:59
2
6 08:00 09:00
5 09:00 10:00
[align=left]Sample Output[/align]
11
6
//区间覆盖,总结一下,共两种:
//(1)最多,区间逐个遍历每个(时间)点
//(2)至少问题:结束时间排序,记录区间个数
//区间覆盖,总结一下,共两种: //(1)最多,区间逐个遍历每个(时间)点 //(2)至少问题:结束时间排序,记录区间个数 #include<cstdio> #include<cstring> #include<algorithm> using namespace std; bool cmp(int x,int y) { return x>y; } int main() { int num,ts,te; int t,n,h1,m1,h2,m2,s[10010]; int minn,maxn; scanf("%d",&t); while(t--) { memset(s,0,sizeof(s)); scanf("%d",&n); minn=0; maxn=1500; for(int i=0;i<n;i++) { scanf("%d %d:%d %d:%d",&num,&h1,&m1,&h2,&m2); ts=h1*60+m1; te=h2*60+m2; if(minn>ts) minn=ts; if(maxn<te) maxn=te; for(int i=ts;i<te;i++) s[i]+=num; } sort(s+minn,s+maxn+1,cmp); printf("%d\n",s[minn]); } return 0; }
相关文章推荐
- Android之使用URLConnection进行网络编程
- bzoj3884: 上帝与集合的正确用法 欧拉降幂公式
- MySQL C API
- Codeforces Round #363 (Div. 2) C. Vacations
- Biee 迁移和刷新GUIDs
- C语言中的单引号和双引号的区别
- margin之百分比
- HDOJ 2018 母牛的故事
- 大数据spark蘑菇云行动前传第5课:零基础彻底实战Scala函数式编程及Spark源码解析
- 常用算法思想之:递归思想
- linux基础入门
- ubuntu 用root登陆图形界面
- Codeforces 468B Two Sets(超直白解释)
- CodeForces 489B BerSU Ball (贪心)
- UVALive 2756 Crazy tea party
- 初探Python(1)
- 线段香蕉
- Doing Homework again (贪心)
- 实验项目3-5:求链表线性表的倒数第K项
- 思路:如何跳过CreateProcess调用底层创建进程函数