UVa 12100 - Printer Queue【队列和优先队列】
来源:互联网 发布:知乎女性精神洁癖 编辑:程序博客网 时间:2024/05/06 08:53
原题网址:
https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=836&page=show_problem&problem=3252
题目说的是,有一些打印任务,每次只打印这些中最重要的,如果当前任务不是最重要的,就放在队尾,现在指定某一位置的一个任务,问什么时候把指定任务打印完成(打印每个需要 1 )
题解:
用的优先队列判断是否是最大的那个值,其实不需要优先队列,只是顺手了而已,然后注意标记上自己的任务,无脑循环模拟。
#include<stdio.h>#include<string.h>#include<queue>using namespace std;struct node{int val,kase;bool friend operator < (node a,node b){return a.val<b.val; }};int main(){int t,n,m;//freopen("shuju.txt","r",stdin);scanf("%d",&t);while(t--){scanf("%d%d",&n,&m);priority_queue<node> pq;queue<node> q;int val,kase;for(int i=0;i<n;++i){scanf("%d",&val);kase=(m==i)?1:0;node tp={val,kase};pq.push(tp);q.push(tp);}int time=0;while(1){node a=pq.top(),b=q.front();while(a.val!=b.val){q.push(b);q.pop();a=pq.top(),b=q.front();}++time;pq.pop();q.pop();if(b.kase==1){printf("%d\n",time);break;} }}return 0;}
0 0
- UVA 12100 Printer Queue(队列,优先队列)
- UVa 12100 - Printer Queue【队列和优先队列】
- Printer Queue 打印队列 UVA 12100
- uva 12100 Printer Queue(打印队列)模拟
- queue队列-printer queue
- 5-7 UVA 12100 Printer Queue打印队列
- UVa 12110 Printer Queue(特殊队列)
- uva12100 Printer Queue (队列模拟, 据说是优先队列,错了)
- Printer Queue打印队列
- 打印队列(Printer Queue)
- uva 12100 Printer Queue 优先级队列模拟题 数组模拟队列
- 队列Queue类 基数排序和优先队列
- UVa12100 Printer Queue (打印队列)
- UVA12100:Printer Queue(打印队列)
- uva 12100 Printer Queue 习题5-7 打印队列 (STL deque练习)
- 关于“打印队列 Printer Queue, ACM/ICPC NWERC 2006, UVa 12100)"的讨论
- UVa 12100 Printer Queue
- UVA - 12100 Printer Queue
- 位 字节 千字节 兆字节 (bit Byte KByte MByte GByte TByte)
- transient 序列化的关键字
- js用jsonp跨域问题
- 从Eclipse迁移到Android Stdio中
- centos7.2 yum 安装tomcat的问题
- UVa 12100 - Printer Queue【队列和优先队列】
- python学习日记_第十天(ex25~26)
- 【2015城市足迹】行万里路,读万卷书
- 糟糕的css用法 1
- 21-《电子入门趣谈》第四章_自己制作电路板-4.2洞洞板的介绍和经典案例使用教程
- graphx操作实例01-edgeListFile导入数据
- jQuery EasyUIcombobox 自动补全
- 自定义view--虚线的绘制
- maven向本地仓库导入官方仓库没有的jar包