水题,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的更多相关文章

  1. [刷题]算法竞赛入门经典(第2版) 5-7/UVa12100 - Printer Queue

    题意:一堆文件但只有一个打印机,按优先级与排队顺序进行打印.也就是在一个可以插队的的队列里,问你何时可以打印到.至于这个插队啊,题目说"Of course, those annoying t ...

  2. Printer Queue

    Description The only printer in the computer science students' union is experiencing an extremely he ...

  3. POJ 3125 Printer Queue

    题目: Description The only printer in the computer science students' union is experiencing an extremel ...

  4. 12100 Printer Queue(优先队列)

    12100 Printer Queue12 The only printer in the computer science students’ union is experiencing an ex ...

  5. uva 12100 Printer Queue

    The only printer in the computer science students' union is experiencing an extremely heavy workload ...

  6. J - Printer Queue 优先队列与队列

    来源poj3125 The only printer in the computer science students' union is experiencing an extremely heav ...

  7. UVa 12100 Printer Queue(queue或者vector模拟队列)

    The only printer in the computer science students' union is experiencing an extremely heavy workload ...

  8. Printer Queue UVA - 12100

    The only printer in the computer science students' union is experiencing an extremely heavy workload ...

  9. 从deque到std::stack,std::queue,再到iOS 中NSArray(CFArray)

    从deque到std::stack,std::queue,再到iOS 中NSArray(CFArray) deque deque双端队列,分段连续空间数据结构,由中控的map(与其说map,不如说是数 ...

随机推荐

  1. Java课程设计 201521123078

    计时器 掌握java图形界面操作以及多线程技术. 1.Mythread1 写一个类Mythread1实现Runnable,当需要开一个线程时就是用这个类.其中的run()通过标记flag和循环实现时间 ...

  2. 201521123090《Java程序设计》第12周学习总结

    本周学习总结 1.1 以你喜欢的方式(思维导图或其他)归纳总结多流与文件相关内容. 书面作业 将Student对象(属性:int id, String name,int age,double grad ...

  3. Eclipse rap 富客户端开发总结(12) :Rap 优化之组件的销毁

    一.概述      经过几个月的rap 项目实战,总结了一些小经验,在这里总结一下,希望对大家有所帮助. 二.销毁的处理       相信学习rap 的同学都知道,swt 中提供了许多的组件,像lab ...

  4. Hibernate第五篇【inverse、cascade属性详解】

    前言 上一篇博文已经讲解了一对多和多对一之间的关系了,一对多和多对一存在着关联关系(外键与主键的关系).本博文主要讲解Inverse属性.cascade属性.这两个属性对关联关系都有影响 Invers ...

  5. TCP/IP中你不得不知的十大秘密

    这段时间 有一点心很浮躁,不过希望自己马上要矫正过来.好好学习编程!这段时间我想好好地研究一下TCP/IP协议和网络传输这块!加油 一.TCP/IP模型 TCP/IP协议模型(Transmission ...

  6. mybatis快速入门(五)

    今天写写user表和orders表的mybatis的高级映射,一对一映射和一对多映射 1.创建一个orders.java文件 1.1一对一映射,一条订单对应一个用户 package cn.my.myb ...

  7. Redis——windows环境安装redis和redis sentinel部署

    一:Redis的下载和安装 1:下载Redis Redis的官方网站Download页面,Redis提示说:Redis的正式版不支持Windows,要Windows学习Redis,请点击Learn m ...

  8. 洗礼灵魂,修炼python(6)--活起来的代码+列表

    活起来的用法: 使用input内置函数 注意python2中和python3中,input函数是不太一样的,python2中,input用户传入什么类型就是什么类型而python3中,不管传入什么类型 ...

  9. 关于JetBrains CLion 激活 (CLion License Activation)的解决办法,带hosts详细修改

    CLion版本号:JetBrains CLion 2017.2.1 第一行选择Activite,第二行Activate license with:选择Activation code. 这个时候里面的代 ...

  10. hdu3974 找上属的模拟

    There is a company that has N employees(numbered from 1 to N),every employee in the company has a im ...