【HDU 4883】TIANKENG’s restaurant(区间更新)
2016-04-25 11:19
417 查看
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
22
6 08:00 09:00
5 08:59 09:59
2
6 08:00 09:00
5 09:00 10:00
Sample Output
116
题目大意
有n个旅行团去餐厅吃饭,每个旅行团有x个人,并且他们到达店铺的时间和离店时间已知,求至少需要几张椅子可以让每一个旅行团到达时都有椅子坐。思路
题目不难,以时间为单位不断去更新区间,如果有旅行团在s时刻到了店铺,就将需要的椅子总数sum[s]+=temp,temp表示这个旅行团的人数,如果某个旅行团在e时间离开了饭店,那么就将椅子总数sum[e]-=temp,那么我任意一个时刻time需要的椅子数就是当前时刻的椅子数sum[time]+sum[time-1],最后跑一遍循环找到最大一个sum输出即可。代码
#include <iostream> #include <cstdio> #include <cstring> #include <algorithm> using namespace std; const int maxn=1500; int sum[maxn],t,n; int main() { scanf("%d",&t); while(t--) { scanf("%d",&n); memset(sum,0,sizeof(sum)); for(int i=0;i<n;i++) { int temp,h1,h2,m1,m2; scanf("%d %d:%d %d:%d",&temp,&h1,&m1,&h2,&m2); int sta=h1*60+m1; int end=h2*60+m2; sum[sta]+=temp; sum[end]-=temp; } int ans=sum[0]; for(int i=1;i<=1440;i++) { sum[i]+=sum[i-1]; ans=max(ans,sum[i]); } printf("%d\n",ans); } return 0; }
相关文章推荐
- android---------版本控制工具Git的使用
- '@P0'附近有语法错误
- TCP/IP 总结
- [改善Java代码]建议40:匿名类的构造函数很特殊
- 160421、MyBatis批量插入数据
- 关于Android侧使用AES进行加解密时的key和iv使用的方法
- velocity
- Bootstrap每天必学之按钮(Button)插件
- 4000 linux系统CentOS下调整home和根分区大小的方法
- Ubuntu完全教程,让你成为Ubuntu高手!
- java继承覆盖总结
- 元数据
- 多线程基础
- PKG_CONFIG_PATH学习小结
- matlab——ddencmp()函数
- 学生各门课程成绩统计SQL语句大全
- 160420、zTree获取所有选中节点数据
- nagios安装
- 怎样在线合并PDF文件
- BeanUtils组件