题解:[HNOI2003]操作系统
十分简单的堆qwq
话说这两天luogu评测机是要炸了么
1 #include<iostream> 2 #include<algorithm> 3 #include<cstdio> 4 #include<cstring> 5 #include<queue> 6 using namespace std; 7 struct node{ 8 int id, ar, w, first;//进程号,到达时间,执行时间,优先级 9 bool operator < (const node &a)const{//按照优先级从大到小,到达时间从早到晚排序 10 if(first==a.first) return ar>a.ar; 11 else return first<a.first; 12 } 13 }; 14 node a; 15 long long end; 16 priority_queue <node> q; 17 int main(){ 18 while(scanf("%d%d%d%d",&a.id,&a.ar,&a.w,&a.first)!=EOF){ 19 while(!q.empty() && end+q.top().w<=a.ar){ 20 node b=q.top(); 21 q.pop(); 22 printf("%d %lld\n", b.id, end+b.w); 23 end+=b.w; 24 } 25 if(!q.empty()){ 26 node d=q.top(); 27 q.pop(); 28 d.w=d.w-a.ar+end; 29 q.push(d); 30 } 31 q.push(a); 32 end=a.ar; 33 } 34 while(!q.empty()){ 35 node c=q.top(); 36 q.pop(); 37 end+=c.w; 38 printf("%d %lld\n", c.id, end); 39 } 40 return 0; 41 }
"Hello World!"