水题,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. 201521123039 《java程序设计》第十二周学习总结

    1. 本周学习总结 2. 书面作业 将Student对象(属性:int id, String name,int age,double grade)写入文件student.data.从文件读出显示. 字 ...

  2. Java多线程高并发学习笔记(二)——深入理解ReentrantLock与Condition

    锁的概念 从jdk发行1.5版本之后,在原来synchronize的基础上,增加了重入锁ReentrantLock. 本文就不介绍synchronize了,有兴趣的同学可以去了解一下,本文重点介绍Re ...

  3. NativeScript官方书籍:NativeScript-用你现有技术构建移动应用程序

    大家好,我用nativescript做企业级移动应用开发一年多了.从最初只能看nativescript英文文档,到现在看到官方发布正式的书籍,感觉nativescript变得越来越好. 当然,在这个过 ...

  4. Ubuntu Server 17.04安装GNOME指令

    短短几行指令,从安装到打开: apt-get install gnome-shell apt-get install xinit xshell 开启  关闭: Ctrl+Alt+F1   Ctrl+A ...

  5. SpringMVC HelloWorld实例开发及部署

    SpringMVC HelloWorld实例开发及部署 2017-01-24 目录 1 Tomcat及Eclipse Tomcat插件安装配置  1.1 Tomcat的安装  1.2 Eclipse ...

  6. CSS的常用属性

    刚开始学习前段的我,还处于初级阶段,一些东西还是会有搞不明白的时候,还是要大家多多理解.今说就一些关于CSS的常用属性吧! 一.CSS常用选择器 CSS选择器应该说是一个非常重要的工具吧,选择器用得好 ...

  7. H5上传图片并使用canvas制作海报

    马上就要"十一"国庆节了,又恰逢公司已经三周岁了,所以市场部和产品共同策划了一个"正青春,共成长"的主题代言活动,准备在国庆节以及中秋节期间让公司员工和用户为公 ...

  8. 【BZOJ】 2463 [中山市选2009]谁能赢呢?(博弈论)

    Description   小明和小红经常玩一个博弈游戏.给定一个n×n的棋盘,一个石头被放在棋盘的左上角.他们轮流移动石头.每一回合,选手只能把石头向上,下,左,右四个方向移动一格,并且要求移动到的 ...

  9. hdu2157矩阵快速幂

    How many ways?? Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) ...

  10. 1001 数组中和等于K的数对 1002 数塔取数问题 1003 阶乘后面0的数量 1004 n^n的末位数字 1009 数字1的数量

    1001 数组中和等于K的数对 基准时间限制:1 秒 空间限制:131072 KB 分值: 5 难度:1级算法题 给出一个整数K和一个无序数组A,A的元素为N个互不相同的整数,找出数组A中所有和等于K ...