uvalive 3135 Argus
https://vjudge.net/problem/UVALive-3135
题意:
有一个系统有多个指令,每个指令产生一个编号为qnum的时间,每个指令的触发间隔不相同,现在给出若干个指令,现在的任务是模拟前k个事件。
如果时间在同一时间发生,那么qnum小的先输出。
思路:
很多相同的数值在同一时刻内,数值小的先输出,那么就是求若干个中最小的,那么就可以用优先队列进行维护。
这里,因为时间范围较小,之后每个事件的时间取余,那么符合的就把一个结构体扔进优先队列,这个结构体包括了qnum,period以及time。
我们重载 < 的时候,发生时间相同的话,把qnum小的优先级调高,时间不同的话,时间在前的优先级高。
代码:
#include <string>
#include <iostream>
#include <queue>
using namespace std; struct node
{
int num;
int pe;
int ti; bool operator < (const node& rhs) const
{
if (ti == rhs.ti) return num > rhs.num;
return ti > rhs.ti;
}
} a[]; priority_queue<node> pq; int main()
{
int cnt = ; string b; while (cin >> b)
{
if (b[] == '#') break; cin >> a[cnt].num >> a[cnt].pe; cnt++;
} int k; cin >> k; for (int i = ;i <= ;i++)
{
for (int j = ;j < cnt;j++)
{
if (i % a[j].pe == )
{
node tmp = (node){a[j].num,a[j].pe,i}; pq.push(tmp);
}
}
} for (int i = ;i < k;i++)
{
node tmp = pq.top();pq.pop(); cout << tmp.num << endl;
} return ;
}
uvalive 3135 Argus的更多相关文章
- 【暑假】[实用数据结构]UVAlive 3135 Argus
UVAlive 3135 Argus Argus Time Limit: 3000MS Memory Limit: Unknown 64bit IO Format: %lld & %l ...
- uva11997 K Smallest Sums&&UVALive 3135 Argus(优先队列,多路归并)
#include<iostream> #include<cstdio> #include<cstdlib> #include<cstring> #inc ...
- uvalive 3135 Argus priority_queue
用优先队列维护每个时间点优先级最高的元素. #include<iostream> #include<cstdio> #include<cstdlib> #inclu ...
- Argus UVALive - 3135(优先队列 水题一道)
有一系列的事件,它每Period秒钟就会产生编号为qNum的事件,你的任务是模拟出前k个事件,如果多个事件同时发生,先处理qNum小的事件 今天再看看数据结构.. #include <iostr ...
- LA 3135 - Argus
看题:传送门 大意就是让你编写一个称为argus的系统,这个系统支持一个register的命令: Register Q_num Period 该命令注册了一个触发器,它每Period秒就会残生一个编 ...
- LA-3135 - Argus(优先队列)
3135 - Argus A data stream is a real-time, continuous, ordered sequence of items. Some examples incl ...
- LA 3135 (优先队列) Argus
将多个有序表合并成一个有序表就是多路归并问题,可用优先队列来解决. #include <cstdio> #include <queue> using namespace std ...
- UVALive - 4108 SKYLINE[线段树]
UVALive - 4108 SKYLINE Time Limit: 3000MS 64bit IO Format: %lld & %llu Submit Status uDebug ...
- UVALive - 3942 Remember the Word[树状数组]
UVALive - 3942 Remember the Word A potentiometer, or potmeter for short, is an electronic device wit ...
随机推荐
- loadrunner scripts
1. ReadFile: Action(){ int count,total=0; char buffer [50]; long file_stream; char * filename = &quo ...
- box-sizing怪异盒子模型在移动端应用
盒子模型不必多少,公认的盒子模型 总宽度=width + padding(padding-left,padding-right) + border(border-left,border-right) ...
- python __name__ 变量的含义
python __name__ 变量的含义 if __name__ == '__main__': tf.app.run() 当python读入程序时,会初始化一些系统变量.如果当前程序是主程序,__n ...
- 使用HttpGet请求json数据
- js实现换肤效果
一,js换肤的基本原理 基本原理很简单,就是使用 JS 切换对应的 CSS 样式表文件.例如导航网站 Hao123 的右上方就有网页换肤功能.除了切换 CSS 样式表文件之外,通常的网页换肤还需要通过 ...
- 轻谈 return i++
在写函数的时候,发现了又一个很有意思的事情 先上代码 public class Test{ static int number = 2; public static void main(String ...
- 第五次作业2、请将该code进行代码重构,使之模块化,并易于阅读和维护;
1.请运行下面code,指出其功能: (需附运行结果截图,并用简短文字描述其功能) 显示了人的姓名.年龄 2.请将该code进行代码重构,使之模块化,并易于阅读和维护: 3.观看视频The Exper ...
- 【Beta】Daily Scrum Meeting——Day2
站立式会议照片 1.本次会议为第一次Meeting会议: 2.本次会议在中午12:00,在图书馆一楼楼道召开,本次会议为30分钟讨论今天要完成的任务以及接下来的任务安排. 燃尽图 每个人的工作分配 成 ...
- 团队作业4——第一次项目冲刺(Alpha版本)7th day
一.Daily Scrum Meeting照片 二.燃尽图 三.项目进展 在计时模式下能够记录用户的用户名和成绩,没有弄登录功能, 将程序定义为单机的 未完成的卡片为登录功能和使用QQ登录. 四.困难 ...
- 201521123076《java程序设计》第三周学习总结
1. 本周学习总结 2.书面作业 Q1.代码阅读 public class Test1 { private int i = 1;//这行不能修改 private static int j = 2; p ...