zoukankan      html  css  js  c++  java
  • 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;
    }
    等我把重载搞懂了再回来写一遍
  • 相关阅读:
    SpringDataRedis 常用命令
    Java 连接 Redis
    Java 循环标记
    初学Docker
    线程池,进程和线程的理解
    Linux-定时器任务
    Linux 命令2
    Linux命令
    Java基础整理
    微服务简介
  • 原文地址:https://www.cnblogs.com/hua-dong/p/7603939.html
Copyright © 2011-2022 走看看