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,不如说是数 ...
随机推荐
- 201521123038 《Java程序设计》 第五周学习总结
201521123038 <Java程序设计> 第五周学习总结 1. 本周学习总结 2. 书面作业 1.代码阅读:Child压缩包内源代码 1.1 com.parent包中Child.ja ...
- 201521123016 《Java程序设计》第5周学习总结
1. 本周学习总结 1.1 尝试使用思维导图总结有关多态与接口的知识点. 2. 书面作业 1.代码阅读:Child压缩包内源代码 1.1 com.parent包中Child.java文件能否编译通过? ...
- 201521123038 《Java程序设计》 第四周学习总结
201521123038 <Java程序设计> 第四周学习总结 1. 本周学习总结 1.1 尝试使用思维导图总结有关继承的知识点. 1.2 使用常规方法总结其他上课内容. 1.通过 ins ...
- DNS原理总结及其解析过程详解
一.域名系统 1.域名系统概述 域名系统DNS(Domain Name System)是因特网使用的命名系统,用来把便于人们使用的机器名字转换成为IP地址.域名系统其实就是名字系统.为什么不叫&quo ...
- java课程设计团队博客
java课程设计 本组主题:Calculator(简易计算器) 功能要求:基本实现计算器的功能,可运行加.减.乘.除.求倒数.求平方根.求百分号运算.正负数运算等 一.团队介绍 团队名称:熬夜做不出随 ...
- Eclipse rap 富客户端开发总结(10) : Rap不同系统间的差异和处理方式
平常进行 rap 程序开发一般都是在 win 下面完成 , 然后在 tomcat 下面测试 , 但是程序最终发布一般都是在 linux aix 上面 , 这个时候就有能会出现一下问题,下面 2 个问 ...
- 警惕Java编译器中那些“蜜糖”陷阱
一.前言 随着Java编译器不断地向前发展,它为程序员们提供了越来越多的“蜜糖”(compiler suger),极大地方便了程序的开发,例如,foreach的增强模式,自动拆箱与装箱以及字符串的连接 ...
- bzoj 3212 Pku3468 A Simple Problem with Integers
3212: Pku3468 A Simple Problem with Integers Time Limit: 1 Sec Memory Limit: 128 MB Description You ...
- Valgrind检测内存泄露简介
原文地址: Valgrind 概述 体系结构 Valgrind是一套Linux下,开放源代码(GPL V2)的仿真调试工具的集合.Valgrind由内核(core)以及基于内核的其他调试工具组成.内核 ...
- python pyinstaller打包exe暗坑1
环境 python2.7.9 win-xp 今天打包了一个小脚本,结果打开报错