POJ 3125 Printer Queue
题目:
Description
The only printer in the computer science students' union is experiencing an extremely heavy workload. Sometimes there are a hundred jobs in the printer queue and you may have to wait for hours to get a single page of output.
Because some jobs are more important than others, the Hacker General has invented and implemented a simple priority system for the print job queue. Now, each job is assigned a priority between 1 and 9 (with 9 being the highest priority,
and 1 being the lowest), and the printer operates as follows.
- The first job J in queue is taken from the queue.
- If there is some job in the queue with a higher priority than job J, thenmove J to the end of the queue without printing it.
- Otherwise, print job J (and do not put it back in the queue).
In this way, all those importantmuffin recipes that the Hacker General is printing get printed very quickly. Of course, those annoying term papers that others are printing may have to wait for quite some time to get printed, but that's life.
Your problem with the new policy is that it has become quite tricky to determine when your print job will actually be completed. You decide to write a program to figure this out. The program will be given the current queue (as a list of priorities) as well as the position of your job in the queue, and must then calculate how long it will take until your job is printed, assuming that no additional jobs will be added to the queue. To simplifymatters, we assume that printing a job always takes exactly one minute, and that adding and removing jobs from the queue is instantaneous.
Input
- One line with two integers n and m, where n is the number of jobs in the queue (1 ≤ n ≤ 100) and m is the position of your job (0 ≤ m ≤ n −1). The first position in the queue is number 0, the second is number 1, and so on.
- One linewith n integers in the range 1 to 9, giving the priorities of the jobs in the queue. The first integer gives the priority of the first job, the second integer the priority of the second job, and so on.
Output
Sample Input
3
1 0
5
4 2
1 2 3 4
6 0
1 1 9 1 1 1
Sample Output
1
2
5 题目大意:
打印一批文件,但文件有优先级别。从前往后扫描,若该作业优先级别已是最高,则执行此作业。若不是,放到队列末尾。求指定位置的作业W被执行的时间。 代码如下:^-^
#include<iostream>
#include<stdio.h>
using namespace std; int a[*],m,n; int sousou()
{
int frontt=,i,maxx,time=;
while()
{
maxx=a[frontt];
for(i=frontt;i<m;i++)
if(a[i]>maxx)
{
if(frontt==n) n=m;
a[m++]=a[frontt++];
break;
}
else
if(i==m-)
{
time++;
if(frontt==n) return time;
frontt++;
}
}
}
//这道题弄了很久.................结果是等号多打了一个................T T
POJ 3125 Printer Queue的更多相关文章
- (队列的应用5.3.3)POJ 3125 Printer Queue(优先队列的使用)
/* * POJ_3125.cpp * * Created on: 2013年10月31日 * Author: Administrator */ #include <iostream> # ...
- POJ 3125 Printer Queue(队列,水题)
题意:有多组数据,每组数据给出n,m,n表示需要打印的文件个数,m表示要打印的目标位置(m为0~n-1). 接下来给出n个数,第i个值对应第i-1个位置的优先级大小. 打印规则如下: ...
- Printer Queue
Description The only printer in the computer science students' union is experiencing an extremely he ...
- 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 ...
- POJ 3481 Double Queue STLmap和set新学到的一点用法
2013-08-08 POJ 3481 Double Queue 这个题应该是STL里较简单的吧,用平衡二叉树也可以做,但是自己掌握不够- -,开始想用两个优先队列,一个从大到小,一个从小到大,可是 ...
- [刷题]算法竞赛入门经典(第2版) 5-7/UVa12100 - Printer Queue
题意:一堆文件但只有一个打印机,按优先级与排队顺序进行打印.也就是在一个可以插队的的队列里,问你何时可以打印到.至于这个插队啊,题目说"Of course, those annoying t ...
- 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 ...
随机推荐
- PHPCMS二次开发教程
PHPCMS V9 结构设计 根目录|–api 结构文件目录|–caches 缓存文件目录 |– configs 系统配置文件目录 |– caches_* 系统缓存目录|–phpcms p ...
- windows下的SASS/Compass的安装与卸载
认识SASS/Compass SASS是一种CSS的开发工具,提供了许多便利的写法,大大节省了设计者的时间,使得CSS的开发,变得简单和可维护. SASS与Compass的安装说明 SASS在Wind ...
- TDirectory.IsEmpty判断指定目录是否为空
使用函数: System.IOUtils.TDirectory.IsEmpty class function IsEmpty(const Path: string): Boolean; static; ...
- #Leet Code# Evaluate Reverse Polish Notation
描述:计算逆波兰表达法的结果 Sample: [", "*"] -> ((2 + 1) * 3) -> 9 [", "/", & ...
- 【转】【Top 100 Best Blogs for iOS Developers】
原文地址:http://www.softwarehow.com/best-blogs-for-ios-developers/ (by JP Zhang | Last updated: Apr 5, 2 ...
- STM32之串口通信
一.RS232通信协议 1.概念 个人计算机上的通讯接口之一,由电子工业协会(Electronic Industries Association,EIA) 所制定的异步传输标准接口. 2.电气特性 逻 ...
- asp.net学习资源汇总
名称:快速入门地址:http://chs.gotdotnet.com/quickstart/描述:本站点是微软.NET技术的快速入门网站,我们不必再安装.NET Framework中的快速入门示例程序 ...
- 安装pip之后,执行pip,提示:unknown or unsupported command install
安装pip之后,在dos命令框中输入pip,提示:unknown or unsupported command install,搜索之后,立马在:http://stackoverflow.com/qu ...
- Python脚本调用C#代码数据交互示例(hello world)
原地址: http://www.djangochina.cn/forum.php?mod=viewthread&tid=247 随着项目的逐渐收尾, 对IronPython脚本也越来越熟悉,这 ...
- mysql注入攻击及防范
一.注入攻击种类 1. GET注入 输入参数通过URL发送. 2. POST注入 输入参数通过HTTP正文发送 3. COOKIE注入 ...