poj1741,poj 2051 Argus

 2023-10-18 阅读 27 评论 0

摘要:// 題意: 給出一些查詢口令,每個命令有一個編號和一個周期,輸出前k個執行的命令的編號.// sample里要求輸出前5個執行的命令的編號,那么前5個執行的時間分別為// 時間點:200(編號:2004), 300(2005), 400(2004), 600(2004), 600(2005)// 兩個命令都能達到600這個時間點,
// 題意: 給出一些查詢口令,每個命令有一個編號和一個周期,輸出前k個執行的命令的編號.
// sample里要求輸出前5個執行的命令的編號,那么前5個執行的時間分別為
// 時間點:200(編號:2004), 300(2005), 400(2004), 600(2004), 600(2005)
// 兩個命令都能達到600這個時間點,但根據題意先輸出編號小的,即先輸出2004

#include<iostream> //優先隊列
#include<string>

#include<queue>
using namespace std;
struct Node
{
int p,id; //id 代表 ID-number, p 代表 Period
int t; //t 代表 請求到達的時間點
bool operator<(const Node& other) const

{
if(t==other.t)
return id>other.id; //時間點相等時編號小的先出隊
else

return t>other.t; //時間點小的先出隊
}

}node;
priority_queue<Node> q;
int main()
{
char s[10];
while(scanf("%s",s)&&strcmp(s,"#")!=0)
{
scanf("%d%d",&node.id,&node.p);
node.t=node.p;
q.push(node);
}
int k;
scanf("%d",&k);
while(k--) //輸出前k個執行的命令的編號
{

node = q.top();
q.pop();
printf("%d\n",node.id);
node.t+=node.p;
q.push(node);
}
return 0;
}

轉載于:https://www.cnblogs.com/mjc467621163/archive/2012/03/13/2395237.html

版权声明:本站所有资料均为网友推荐收集整理而来,仅供学习和研究交流使用。

原文链接:https://hbdhgg.com/4/148116.html

发表评论:

本站为非赢利网站,部分文章来源或改编自互联网及其他公众平台,主要目的在于分享信息,版权归原作者所有,内容仅供读者参考,如有侵权请联系我们删除!

Copyright © 2022 匯編語言學習筆記 Inc. 保留所有权利。

底部版权信息