[HNOI2003]操作系统
生活随笔
收集整理的這篇文章主要介紹了
[HNOI2003]操作系统
小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
https://www.luogu.org/problemnew/show/P2278
題解:
一個(gè)是還未開始的進(jìn)程,另一個(gè)是按照優(yōu)先級排序的等待進(jìn)程;
每次做時(shí)比較兩個(gè)序列的隊(duì)頭,如果是當(dāng)前在運(yùn)行的進(jìn)程先結(jié)束,
則把此進(jìn)程輸出,并將其彈出優(yōu)先隊(duì)列;如果是下一個(gè)進(jìn)程要開始,
則先結(jié)算當(dāng)前在運(yùn)行的進(jìn)程的剩余時(shí)間,并將下一個(gè)進(jìn)程加入優(yōu)先隊(duì)列;
(原來endl和‘\n’真的有本質(zhì)的區(qū)別)
/* *@Author: STZG *@Language: C++ */ #include <bits/stdc++.h> #include<iostream> #include<algorithm> #include<cstdlib> #include<cstring> #include<cstdio> #include<string> #include<vector> #include<bitset> #include<queue> #include<deque> #include<stack> #include<cmath> #include<list> #include<map> #include<set> //#define DEBUG #define RI register int using namespace std; typedef long long ll; //typedef __int128 lll; const int N=1500000+10; const int M=100000+10; const int MOD=1e9+7; const double PI = acos(-1.0); const double EXP = 1E-8; const int INF = 0x3f3f3f3f; int t,n,m,k; int ans,cnt,flag,temp,sum; int a[N]; char str; struct node{int id,start,time,rank;bool operator <(const node &S)const{if(rank==S.rank)return start>S.start;return rank<S.rank;} }e[N],tmp; priority_queue<node>q; int main() { #ifdef DEBUGfreopen("input.in", "r", stdin);//freopen("output.out", "w", stdout); #endifios::sync_with_stdio(false);//cin.tie(0);//cout.tie(0);//scanf("%d",&t);//while(t--){cnt++;while(~scanf("%d%d%d%d",&e[cnt].id,&e[cnt].start,&e[cnt].time,&e[cnt].rank))cnt++;//cout<<cnt<<endl;cnt--;int pos=1;int now=1;for(int i=1;i<=cnt;i++){if(q.empty()){q.push(e[pos]);now=max(now,e[pos].start);pos++;}//cout<<q.top().start<<endl;while(now+q.top().time>e[pos].start&&pos<=cnt){tmp=q.top();//cout<<q.top().id<<endl;q.pop();tmp.time=tmp.time-e[pos].start+now;now=e[pos].start;q.push(tmp);q.push(e[pos]);now=max(now,q.top().start);pos++;}now=max(now,q.top().start)+q.top().time;cout<<q.top().id<<" "<<now<<'\n';q.pop();}//}#ifdef DEBUGprintf("Time cost : %lf s\n",(double)clock()/CLOCKS_PER_SEC); #endif//cout << "Hello world!" << endl;return 0; }?
總結(jié)
以上是生活随笔為你收集整理的[HNOI2003]操作系统的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。