poj 2051 Argus

// 题意: 给出一些查询口令,每个命令有一个编号和一个周期,输出前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;
}

posted on 2012-03-13 23:56  sysu_mjc  阅读(132)  评论(0编辑  收藏  举报

导航