sort()函数的cmp为函数,priority_queue的cmp为类,具体写法是:

struct Node {
  int i,j;
} node[]; struct cmp {
bool operator() (Node a,Node b) {
if(a.i==b.i)
return a.j<b.j;///j的升序
return a.i<b.i;    ///i的升序
}
}; priority_queue<Node,vector<Node>,cmp> re;

#include <iostream>
#include <queue>
using namespace std; typedef struct {
int id;///用户ID
int time;///下一次出该出现的时间
int period;///时间间隔
} Register; ///定义优先权队列的比较函数
struct cmp {
bool operator()(Register a,Register b) {
if(a.time==b.time)
return a.id>b.id;///时间相等时按照id升序排列
return a.time>b.time;///按照时间升序排列,成为最小堆
}
}; int main() {
///定义优先权队列,到达时间最小的最先到,相等时按照id升序排列
priority_queue<Register,vector<Register>,cmp > re;
string cmd;///命令
int id;///定义id
int period;///定义时间间隔
int count;///定义输出条数
while(true) {
cin>>cmd;
if(cmd.compare("#")==)break;
cin>>id>>period;
Register r;
r.id = id;
r.period = period;
r.time = period;
re.push(r);
}
cin>>count;
while(count--) {
Register reg = re.top();
cout<<reg.id<<endl;
reg.time += reg.period;
re.pop();
re.push(reg);
}
return ;
}

最新文章

  1. nodejs pm2部署配置
  2. Object.prototype和Function.prototype一些常用方法
  3. 反汇编工具capstone安装后import error
  4. mac OS X操作 -- 常用
  5. UWP/Win10新特性系列—UserConsentVerifier
  6. APPLICATION ERROR #1502 .
  7. 二级c程序设计题(2)
  8. sql数据库监控语句
  9. Design Pattern——开放封闭原则
  10. JS 数组及函数
  11. 在虚拟机中安装Centos系统
  12. blob对象的应用
  13. 算法之DP
  14. Ubuntu install TensorFlow
  15. 《重构网络-SDN架构与实现》阅读随笔
  16. PHP中刷新输出缓冲详解[转载]
  17. 部署一个flask服务记录
  18. Linux入门——基础系统设置命令
  19. Android 识别身份证号码(图片识别)
  20. 【BZOJ2882】工艺 [SAM]

热门文章

  1. 轻量级RPC框架-motan
  2. 技巧:开启ubuntu系统桌面上的右键进入terminal命令行控制台功能
  3. GM MDI Tech 3 VS GM tech 2
  4. java中使用nextLine(); 没有输入就自动跳过的问题?
  5. 转 python 的常用函数replace, split(),enumerate() 函数
  6. web常见测试点总结
  7. Oracle 配置监听和本地网络服务
  8. golang变量
  9. VBS 操作Excel
  10. PlayMaker Action的执行顺序