UVA12100 Printer Queue 【双端队列】
来源:互联网 发布:淘宝新店引流量 编辑:程序博客网 时间:2024/05/22 06:16
题目链接:https://vjudge.net/problem/UVA-12100
题意:
有 n 个任务,每个任务都有一个优先级,优先级越高则越急。每次从队列首部取出一个任务J。按照如下思路打印:
如果队列里有比 J 更急的任务,则直接吧 J 放到队列尾部。否则进行打印,打印需要1分钟。(放到队列尾部不消耗时间,打印之后扔掉)
给你一个打印队列,求某个任务的打印时间(包括这个任务本身所用的打印时间)。
题解:
这是我的第一道双端队列题= =本来想直接用数组手切,结果发现太麻烦,数组大小也不好算。于是我想到了双端队列= =。
上网自行脑补双端队列有关知识。
然后就水过去了。
附代码:
#include <deque>#include <cstdio>#include <cstring>#include <algorithm>using namespace std;const int size = 105;struct _node{int x;bool isfd;// 表示是否是需要查询的点 }a[size]; int findmx(deque<_node> test) {int mn = -(1 << 26);while(!test.empty()) {mn = max(mn, test.back().x);test.pop_back();}return mn;}int main() {int test;scanf("%d", &test);while( test -- ) {deque<_node> dq;int n, fd;scanf("%d %d", &n, &fd);for ( int i = 0; i < n; i++ ){if(i == fd) a[i].isfd = 1;else a[i].isfd = 0;scanf("%d", &a[i].x); dq.push_back(a[i]);}int ans = 0;while( !dq.empty() ) {int mx = findmx(dq);_node vthis = dq.front();if(vthis.x == mx) {ans ++;dq.pop_front();if(vthis.isfd == 1) {printf("%d\n", ans);break;}} else {dq.push_back(vthis);dq.pop_front();}}}return 0;}
0 0
- UVA12100 Printer Queue 【双端队列】
- UVa12100 Printer Queue (打印队列)
- UVA12100:Printer Queue(打印队列)
- UVa12100 - Printer Queue
- UVA12100 - Printer Queue
- UVa12100 Printer Queue
- UVA12100 Printer Queue
- uva12100 Printer Queue (队列模拟, 据说是优先队列,错了)
- UVALive3638 UVA12100 POJ3125 HDU1972 Printer Queue【队列+模拟】
- 习题5-7 打印队列(Printer Queue, UVa12100)
- 算法竞赛入门经典 第二版 习题5-7 打印队列 Printer Queue uva12100
- queue队列-printer queue
- Uva12100 Printer Queue 【queue+sort】【习题5-7】
- Printer Queue打印队列
- 打印队列(Printer Queue)
- UVA 12100 Printer Queue(队列,优先队列)
- 有关优先对列的题——UVA12100 - Printer Queue
- [刷题]算法竞赛入门经典(第2版) 5-7/UVa12100 - Printer Queue
- 【数据结构与算法】 一些知识点零零总总(引用网络知识点节选重组)
- HiveQL:数据定义
- 109. Convert Sorted List to Binary Search Tree
- CPU Notes
- tomcat注册为系统服务后,项目无法启动或者启动后页面中文乱码
- UVA12100 Printer Queue 【双端队列】
- Android学习笔记之蓝牙通信...
- SVG(可缩放矢量图形)绘制工具Method Draw
- docker原理及基本概念
- 问题四十二:怎么用ray tracing画任意圆环片段
- 【JZOJ 3854】分组
- 程序员面试金典——解题总结: 9.12测试 12.3如何测试国际象棋程序中的移动方法?
- Total size of serialized results of 20 tasks (1088.8 MB) is bigger than spark.driver.maxResultSize (
- java 木马开发(1)