ZOJ2212 Argus 优先队列 结构体

时间:2022-02-18 04:21:06
#include <iostream>
#include <string>
#include <queue>
using namespace std;
struct In
{
int id;
int ReturnTime;
int period;
In(int i, int p):id(i), ReturnTime(p), period(p){}
//重载写在在里面又怎么写?
};
bool operator < (const In& x, const In& y)
{
if(x.ReturnTime != y.ReturnTime)
return x.ReturnTime > y.ReturnTime;
return x.id > y.id;
}//为什么不是小于符号??? int main()
{
string str;
int k, id, period;
priority_queue<In> que;
for(int i = ; cin >> str; ++i)
{
if(str == "#") break;
else
cin >> id >> period;
In tmp(id, period);
que.push(tmp);
}
cin >> k;
while(k--)
{
In tmp = que.top();
que.pop();
cout << tmp.id << endl;
tmp.ReturnTime += tmp.period;
que.push(tmp);
}
return ;
}
等我把重载搞懂了再回来写一遍