传送门:https://uva.onlinejudge.org/external/121/12100.pdf

题意:队列中待打印的任务(1 <= n <= 100)带有优先级(1-9), 打印步骤为每次从队首拿出一个, 如果队列中没有优先级比该任务高的, 打印这个任务; 若有优先级高的, 把这个任务放到队尾,  并打印优先级最高的. 每打印一次耗时1分钟, 求给定任务什么时候打印.

水题A半天    不愧是弱渣..........

最坏的情况需要maxn*maxn的空间........

front  rear  记录前后位置

 #include <bits/stdc++.h>
using namespace std; const int MAXN = ;
int t, n, m, _time;
int que[MAXN*MAXN]; void process(){
int front = , rear = n;
while(true){
int maxi = que[front];
for(int i = front; i < rear; ++i){
if(que[i] > maxi){
if(front == m) m = rear;
que[rear++] = que[front++];
break;
}
else if(i == rear - ){
++_time;
if(front == m) return ;
front++;
}
}
}
}
int main(){
cin >> t;
while(t--){
_time = ;
cin >> n >> m;
for(int i = ; i < n; ++i) cin >> que[i];
process();
cout << _time << endl;
}
return ;
}

UVa 12100 Printer Queue (习题 5-7)的更多相关文章

  1. uva 12100 Printer Queue

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

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

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

  3. uva 12100 Printer Queue 优先级队列模拟题 数组模拟队列

    题目很简单,给一个队列以及文件的位置,然后一个一个检查,如果第一个是优先级最高的就打印,否则放到队列后面,求所要打印的文件打印需要花费多长时间. 这里我用数组模拟队列实现,考虑到最糟糕的情况,必须把数 ...

  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(STL队列&优先队列)

    题目 题目     分析 练习STL     代码 #include <bits/stdc++.h> using namespace std; int main() { int t; sc ...

  6. Printer Queue UVA - 12100

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

  7. Printer Queue

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

  8. POJ 3125 Printer Queue

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

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

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

随机推荐

  1. oc内容5大区

    1.堆区(malloc):不需要手动管理内存,自动管理 2.栈区(stack):需要手动管理内存 3.静态区 4.常量区 5.方法区 load类方法:把类加载进内存的时候调用,只会调用一次 initi ...

  2. OpenCV备忘

    都是转来的内容的,算是整理一下 OpenCV备忘 深度和通道的理解 CV_8UC1 是指一个8位无符号整型单通道矩阵, CV_32FC2是指一个32位浮点型双通道矩阵 CV_8UC1 CV_8SC1 ...

  3. chap3 数组 #C

    4.1 数组的基本概念 4.1.1 要点归纳 一维数组 定义: int a[10]; 数组名是一个地址常量,不允许修改. 引用: 初始化: 静态数组 static int a[10];的初值? 全部赋 ...

  4. subsequence/subsets/subarray/substring problems

    128. Longest Consecutive Sequence hashmap, int up = nums[i], int down, int max 注:访问过的要erase 152. Max ...

  5. U3D音频系统

    一.基本信息 1.支持的声音格式 WAV OGG MP3 AIFF MOD S3M xm IT    导入以后,unity会选择的压缩方式: WAV:无损,音质好,文件大,适用于较短文件 OGG.MP ...

  6. android之活动状态、生存期、启动模式

    活动状态:1.运行状态2.暂停状态3.停止状态4.销毁状态 活动的生存期 七个回调方法1.onCreate()2.onStart()3.onResume()4.onPause()5.onStop()6 ...

  7. 在网页边角添加GitHub链接图标

    在网页边角添加GitHub链接图标 在页面添加HTML一下代码: <a href="https://github.com/you"> <img style=&qu ...

  8. AndroidStudio0.5.2 BUG 导致 menu 菜单键崩溃

    郁闷了半天,今天发现一点击手机 menu 键应用就崩溃了,记得之前都是好好的,调试了半天代码还是搞不定,于是网上google了一番,发现仅国外有一两篇文章有提到类似问题,据说是 0.5.2 版本的 B ...

  9. Makfile文件编写

    一.make是什么 GNU make是一个工程管理器,专门负责管理.维护较多文件的处理,实现自动化编译.如果一个工程项目中,有成百上千个代码源文件,若其中一个或多个文件进过修改,make就需要能够自动 ...

  10. [SQL基础教程] 2-2 算数运算符和比较运算符

    [SQL基础教程] 2-2 算数运算符和比较运算符 算数运算符 四则运算 运算符 含义 + - * / SELECT col_1*2 AS col_new FROM table; 注意 所有包含NUL ...