洛谷 P2278 [HNOI2003]操作系统(优先队列)
作者:互联网
题目传送门
解题思路:
一道没啥思维含量的模拟题,但是个人感觉代码实现不简单,可能是我太弱了,花了我6个小时,3次重写.
AC代码:
1 #include<iostream> 2 #include<cstring> 3 #include<queue> 4 #include<cstdio> 5 6 using namespace std; 7 8 struct kkk { 9 int id,st,re,pr; 10 bool operator < (const kkk &a) const { 11 if(pr == a.pr) return st > a.st; 12 else return pr < a.pr; 13 } 14 }; 15 kkk c; 16 long long ti; 17 priority_queue<kkk> q; 18 19 int main() { 20 while(scanf("%d%d%d%d",&c.id,&c.st,&c.re,&c.pr) != EOF) { 21 while(!q.empty() && ti + q.top().re <= c.st) { 22 kkk b = q.top(); 23 q.pop(); 24 printf("%d %lld\n",b.id,ti + b.re); 25 ti += b.re; 26 } 27 if(!q.empty()) { 28 kkk d = q.top(); 29 q.pop(); 30 d.re = d.re - c.st + ti; 31 q.push(d); 32 } 33 q.push(c); 34 ti = c.st; 35 } 36 while(!q.empty()) { 37 kkk f = q.top(); 38 q.pop(); 39 ti += f.re; 40 printf("%d %lld\n",f.id,ti); 41 } 42 43 return 0; 44 }
标签:pr,洛谷,d%,st,re,HNOI2003,kkk,include,P2278 来源: https://www.cnblogs.com/lipeiyi520/p/11286144.html