poj 2051 Argus(优先队列)
                                                            生活随笔
收集整理的這篇文章主要介紹了
                                poj 2051 Argus(优先队列)
小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.                        
                                題目鏈接:?http://poj.org/problem?id=2051
思路分析:
優(yōu)先級(jí)問(wèn)題,使用優(yōu)先隊(duì)列求解;當(dāng)執(zhí)行某個(gè)任務(wù)后,再增加一個(gè)任務(wù)到隊(duì)列中,
該任務(wù)的優(yōu)先級(jí)為執(zhí)行任務(wù)的時(shí)間加上其時(shí)間間隔,如此反復(fù)直到求出前K個(gè)執(zhí)行任務(wù)。
?
代碼:
#include <iostream> #include <queue> using namespace std;struct Argu {int QNum;int period;int time;bool operator<(const Argu &rhs) const{if (time > rhs.time)return true;if (time == rhs.time)return QNum > rhs.QNum;return false;} };int main() {int k;char tmp[10];priority_queue<Argu> heap;while (scanf("%s", tmp) != EOF && strcmp(tmp, "#") != 0){Argu command;scanf("%d%d", &command.QNum, &command.period);command.time = command.period;heap.push(command);}scanf("%d", &k);for (int i = 0; i < k; ++i){Argu ans;ans = heap.top();heap.pop();ans.time += ans.period;heap.push(ans);printf("%d\n", ans.QNum);}return 0; }?
轉(zhuǎn)載于:https://www.cnblogs.com/tallisHe/p/4263265.html
總結(jié)
以上是生活随笔為你收集整理的poj 2051 Argus(优先队列)的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
 
                            
                        - 上一篇: onlyoffice添加删除字体
- 下一篇: 如何在Java中使用表达式_如何在jav
