【结构体排序】HDU4883TIANKENG’s restaurant【BestCoder Round #2】
来源:互联网 发布:软件企业两免三减半 编辑:程序博客网 时间:2024/06/04 00:38
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4883
#include<iostream>#include<cstdio>#include<algorithm>#include<queue>#include<vector>using namespace std;const int N=10005;int n; // group数量struct node{ int sh,sm; int eh,em; int num;}g[N];// 比较两个时间的先后int Compare(int h1,int m1,int h2,int m2){ if(h1>h2) return 1; else if(h1<h2) return -1; if(m1>m2) return 1; else if(m1<m2) return -1; return 0;}// 按开始时间排序bool cmp(node a,node b){ if(a.sh!=b.sh) return a.sh<b.sh; else return a.sm<b.sm;}// 按结束时间排序bool operator< (node a,node b){ if(a.eh!=b.eh) return a.eh>b.eh; else return a.em>b.em;}void Input(){ cin>>n; for(int i=0;i<n;i++){ scanf("%d",&g[i].num); scanf("%d:%d",&g[i].sh,&g[i].sm); scanf("%d:%d",&g[i].eh,&g[i].em); } sort(g,g+n,cmp);// for(int i=0;i<n;i++){// printf("%d ",g[i].num);// printf("%d:%d ",g[i].sh,g[i].sm);// printf("%d:%d\n",g[i].eh,g[i].em);// }}void solve(){ priority_queue<node>q; int Max=0; // 最大椅子数; int M=0; // 剩余可以用的椅子; for(int i=0;i<n;i++){ // 归还已经使用完的椅子; while(!q.empty()){ node tmp=q.top(); if(Compare(tmp.eh,tmp.em,g[i].sh,g[i].sm)<=0){ M+=tmp.num; q.pop(); }else break; } // 新来用户使用椅子; if(M<g[i].num){ // 需要新添椅子 Max+=g[i].num-M; M=0; }else{ // 不需要新添椅子 M-=g[i].num; } q.push(g[i]); } cout<<Max<<endl;}int main(){ int t; cin>>t; while(t--){ Input(); solve(); } return 0;}/*24 8:00 8:015 8:00 8:01*/
阅读全文
0 0
- 【结构体排序】HDU4883TIANKENG’s restaurant【BestCoder Round #2】
- HDU4883TIANKENG’s restaurant
- HDU4883TIANKENG’s restaurant
- BestCoder Round #2 1001 TIANKENG’s restaurant
- BestCoder Round #2-TIANKENG’s restaurant
- BestCoder Round #2 1001TIANKENG’s restaurant
- HDU 4883 TIANKENG’s restaurant(排序或优先队列模拟)——BestCoder Round #2
- hdu4883 & BestCoder Round #2 TIANKENG’s restaurant(暴力)
- BestCoder Round #2 1001 TIANKENG’s restaurant(区间内查找)
- hdu 4883 bestcoder round 2 1001 TIANKENG’s restaurant
- 模拟考试1 BestCoder Round #2 TIANKENG’s restaurant
- 【结构体排序】HDU6015Skip the Class【BestCoder Round #92】
- HDU 4883 TIANKENG’s restaurant Bestcoder 2-1(模拟)
- BestCoder #2 1001 TIANKENG’s restaurant && Nyoj 168 房间安排
- 20140916 【 贪心 】 bestcoder #2 + hdoj 4883 TIANKENG’s restaurant
- HDU 4883 Best Coder Round 2 TIANKENG’s restaurant 题解
- Codeforces 597B: Restaurant(贪心+结构体排序)
- 【BestCoder】#Valentine's Day Round
- 第十二届北京师范大学程序设计竞赛决赛 C. 方(芳)格(哥)取数【思维】
- python学习之路-socket网络编程-day07
- caffemodel中的参数及特征的抽取
- SLAM数据集
- 使用Windows API保存配置参数
- 【结构体排序】HDU4883TIANKENG’s restaurant【BestCoder Round #2】
- DB2移动数据实用工具的使用
- 第十二届北京师范大学程序设计竞赛决赛训练总结【7/10】
- Activiti之命令拦截器
- linux用户和组相关文件
- Day43-Struts01
- 【2017.8.6普及模拟】最大(max)
- POJ 3260 The Fewest Coins(动态规划+多重背包+完全背包)
- Java类的定义与实例化