水题,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. 201521123085 《Java程序设计》第一周学习总结

    一 本周学习总结 学习了Java,又和老师见面了,这学期要好好学习Java了.Java这个东西刚刚接触很难懂,其实现在还是不懂,但是我会慢慢地努力地好好学,上机课第一次在黑色的框框弄出Hello wo ...

  2. 分布式一致性算法Raft

    什么是分布式一致性? 我们先来看一个例子: 我们有一个单节点node,这个节点可以是数据库,也可以是一台服务器,当client向node发送data时,X节点收到data,记录下来 由此可见对于单个节 ...

  3. [09] 监听器 Listener

    1.事件 1.1 事件的概念 在Servlet中有一个概念叫做监听,顾名思义,就是监听某种事件是否发生.就如你是一家娱乐媒体公司的老板,你派出狗仔队去跟着某些明星,比如你想了解他们的绯闻,或者活动进展 ...

  4. [03] Servlet继承关系和生命周期

    1.Servlet的继承关系 假如现有我们自定义的一个Servlet,继承HttpServlet,那么实际上它的继承链如下图:   可以看到,核心的部分在于: 两个顶级接口 Servlet Servl ...

  5. Python生成器主要用法

    代码如下: #!/usr/bin/env python3 # -*- coding: utf-8 -*- __author__ = '人生入戏' def use(name): print(" ...

  6. Failed to start component [StandardEngine[Catalina].StandardHost[localhost].StandardContext[/SpringStruts]]

    今天启动Tomcat时候遇到了这个问题 Failed to start component [StandardEngine[Catalina].StandardHost[localhost].Stan ...

  7. 快速学会require的使用

    快速学会使用require.js 1.get start 先到官网下载requirejs到本地,官方同时提供Node版本r.js,我们只使用requirejs即可. 接下来在页面上写入 <scr ...

  8. Zabbix 添加脚本检测IP变化

    监控环境 IP和HOSTNAME 有时会有变化.但目前是通过IP地址监控,不是DNS名,添加一个外部脚本,发现IP和HOSTNAME发生变化时告警. vim /usr/local/etc/zabbix ...

  9. 【转】开源中国上看到的一个vim的自动配置的好东西,分享下

    https://www.oschina.net/p/onekey-to-vim-ide 变量有高亮,竖行上有直线定位,对python的支持效果更佳,从事C/C++开发的程序员使用也不错.

  10. Vue.js的从入门到放弃进击录(二)

    哇塞,昨晚更新的篇(一)这么多阅读量,看来入坑的人越来越多啦~熬了一个礼拜夜,今天终于生病惹~国庆要肥家咯·所以把篇(二)也更完.希望各位入坑的小伙伴能少跳几个坑呗.如果有什么不对的地方也欢迎讨论指正 ...