在此附上一道优先队列的题目链接:
http://acm.hdu.edu.cn/showproblem.php?pid=4393
此题个人感觉技巧性贼可以的,利用队列把速度相同的入到同一队列,之后只要比较Fi排序,以后依次把101个对首元素提出来即可`
在这里插入#include <iostream>
#include <algorithm>
#include <queue>
using namespace std;
const int maxn = 1e5 + 5;
struct node{
int id;
int f;
bool operator < (const node & rhs)const{
if(f == rhs.f)
{
return id > rhs.id;
}
else return f < rhs.f;
}
};
priority_queue<node>q[105];
int main()
{
int t;
scanf("%d",&t);
int cnt = 1;
while(t--)
{
int n;
scanf("%d",&n);
cout << "Case #" << cnt++ << ":" << endl;
for(int i = 0;i < n;i++)
{
int a,b;
node p;
cin >> a >> b;
p.f = a;
p.id = i + 1;
q[b].push(p);
}
for(int i = 0;i < n;i++)//n代表时间
{
int pos,pid,Max = -1;
for(int j = 1;j < 101;j++)
{
if(!q[j].empty())
{
node p = q[j].top();
if(p.f + j * i > Max ||(p.f + j * i == Max&&p.id<pid))
{
pos = j;
pid = p.id;
Max = p.f + j * i;
}
}
}
if(i != n - 1) cout << pid << " ";
else cout << pid;
q[pos].pop();
}
cout << endl;
}
}
代码片
`