Live2d Test Env

ZOJ2212 Argus 优先队列 结构体

#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 = 0; 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 0;
}
等我把重载搞懂了再回来写一遍

 

posted @ 2017-09-27 21:06  nimphy  阅读(106)  评论(0编辑  收藏  举报