标签:des style blog http java color os strong
Time Limit: 2000/1000 MS (Java/Others)
Memory Limit: 131072/65536 K (Java/Others)
Total Submission(s): 0
Accepted Submission(s): 0
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
标签:des style blog http java color os strong
原文地址:http://www.cnblogs.com/crackpotisback/p/3871880.html