老是交错语言..
比扔石头还简单一点的优先队列
#include<cstdio>
#include<queue>
using namespace std;
struct node
{
int id;
int po;
int le;
bool operator<(const node &a) const
{
if (po==a.po) return id>a.id;
else return po>a.po;
}
};
int main()
{
int k,i;
char s[20];
struct node a;
priority_queue<node>q;
while (scanf("%s",s)&&s[0]!='#')
{
scanf("%d%d",&a.id,&a.le);
a.po=a.le;
q.push(a);
}
scanf("%d",&k);
while (k--)
{
a=q.top();
q.pop();
printf("%d\n",a.id);
a.po+=a.le;
q.push(a);
}
}
本文介绍了一个使用 C++ 实现的简单优先队列应用案例。通过定义结构体节点并重载比较运算符,实现了根据节点的优先级进行排序的功能。文章展示了如何利用优先队列来模拟任务调度的过程。
538

被折叠的 条评论
为什么被折叠?



