UVa12100,Printer Queue
水题,1A过的
数据才100,o(n^3)都能过,感觉用优先队列来做挺麻烦的,直接暴力就可以了,模拟的队列,没用stl
#include <iostream>
#include <cstdio>
#include <string>
#include <cstring>
#include <queue>
#define maxn 100+5
using namespace std;
int mid[maxn],v[maxn],q[maxn*maxn],ans;
int n,m,id;
int init(){
memset(mid,,sizeof(mid));
memset(v,,sizeof(v));
memset(q,,sizeof(q));
cin>>n>>m;
id=;ans=;
for (int i=;i<n;i++){
mid[i]=i;
cin>>v[i];
}
}
int find_max(){
int max=;
for (int i=;i<n;i++)
max=v[i]>max?v[i]:max;
return max;
}
int work(){
int head,tail,max;
head=;tail=n-;
for (int i=;i<n;i++)
q[i]=i;
while (head<tail){
int t=find_max();
if (q[head]==m&&t==v[m]){
break;
}else if (v[q[head]]==t) {
v[q[head]]=;
head++;
ans++;
}else {
tail++;
q[tail]=q[head];
head++;
}
}
}
int main()
{
int T;
cin>>T;
while (T-->){
init();
work();
cout<<ans+<<endl;
}
}
UVa12100,Printer Queue的更多相关文章
- [刷题]算法竞赛入门经典(第2版) 5-7/UVa12100 - Printer Queue
题意:一堆文件但只有一个打印机,按优先级与排队顺序进行打印.也就是在一个可以插队的的队列里,问你何时可以打印到.至于这个插队啊,题目说"Of course, those annoying t ...
- Printer Queue
Description The only printer in the computer science students' union is experiencing an extremely he ...
- POJ 3125 Printer Queue
题目: Description The only printer in the computer science students' union is experiencing an extremel ...
- 12100 Printer Queue(优先队列)
12100 Printer Queue12 The only printer in the computer science students’ union is experiencing an ex ...
- uva 12100 Printer Queue
The only printer in the computer science students' union is experiencing an extremely heavy workload ...
- J - Printer Queue 优先队列与队列
来源poj3125 The only printer in the computer science students' union is experiencing an extremely heav ...
- UVa 12100 Printer Queue(queue或者vector模拟队列)
The only printer in the computer science students' union is experiencing an extremely heavy workload ...
- Printer Queue UVA - 12100
The only printer in the computer science students' union is experiencing an extremely heavy workload ...
- 从deque到std::stack,std::queue,再到iOS 中NSArray(CFArray)
从deque到std::stack,std::queue,再到iOS 中NSArray(CFArray) deque deque双端队列,分段连续空间数据结构,由中控的map(与其说map,不如说是数 ...
随机推荐
- Java-对象排序
在业务逻辑中,我们经常需要对list进行排序,就像下面这样: Collections.sort(l); 如果l中的元素是String类型,你会发现sort方法将使用字母顺序排序.如果l中的元素是Dat ...
- 201521123044 《Java程序设计》第9周学习总结
1. 本章学习总结 2. 书面作业 本次PTA作业题集异常 1.常用异常题目5-1 1.1 截图你的提交结果(出现学号) 1.2 自己以前编写的代码中经常出现什么异常.需要捕获吗(为什么)?应如何避免 ...
- Eclipse rap 富客户端开发总结(14) :rap 图片、数据缓存处理
一.概述 在进行了 rap 的基本学习之后,您对 rap 的理解是否进入了更高的一个层次呢,个人觉得,对学习 rap 的人来说,进行 rap 的学习是一个探索的过程,在编程中不断的对其进行理解和分析, ...
- 设置文件opendilag、savedilog默认路径和文件类型
dlgSave1.Filter:='文件.txt|*.txt;|word文件|*.doc,*.docx'; dlgSave1.InitialDir:=GetCurrentDir; //设置为当前路径 ...
- java基础知识6-- 抽象类,抽象方法,接口,构造方法,类方法等易混淆的知识点
一.抽象类和抽象方法 (B 继承 抽象类A) 抽象类:有抽象方法的一定是抽象类 抽象方法:方法名前有abstract修饰,且方法没有方法体,即{},不需要实现任何功能,只是声明 1.抽象类中的方法有 ...
- Eclipse中删除tomcat server 导致不能重新创建该版本的tomcat server
在Eclipse中创建了一个Web工程后,需要将该工程部署到Tomcat中进行发布.有时就会遇到在New Server对话框中选择了Tomcat 6/7后却无法单击“Next”按钮的问题,如下图所示: ...
- Oracle日期时间操作大全
本文出自:http://www.cnblogs.com/hl3292/archive/2010/11/03/1868159.html oracle sql日期比较: 共三部分: 第一部分:oracle ...
- jz2440重新分区
在购买开发板的时候,板子上已经烧写好了bootloader.内核和文件系统.但是在具体使用时,发现板子上划分的内核分区只有2M,但是我编译出来的内核大于2M,于是将内核烧写到nandflash上面时会 ...
- Android 之http编程
HTTP-GET和HTTP-POST定义: 都是使用HTTP的标准协议动词,用于编码和传送变量名/变量值对参数,并且使用相关的请求语义. 每个HTTP-GET和HTTP-POST都由一系列HTTP请求 ...
- 初识Hibernate之环境搭建
相信所有做后端的程序员同行们,没有不知道Hibernate大名的.这是一个经典的轻量级Java EE持久层的解决方案,它使得我们程序员能以面向对象的思维操作传统的关系型数据库,这也是其存在的 ...