题目:

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 a positive integer: the number of test cases (at most 100). Then for each test case:

  • 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

For each test case, print one line with a single integer; the number of minutes until your job is completely printed, assuming that no additional print jobs will arrive.

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的更多相关文章

  1. (队列的应用5.3.3)POJ 3125 Printer Queue(优先队列的使用)

    /* * POJ_3125.cpp * * Created on: 2013年10月31日 * Author: Administrator */ #include <iostream> # ...

  2. POJ 3125 Printer Queue(队列,水题)

    题意:有多组数据,每组数据给出n,m,n表示需要打印的文件个数,m表示要打印的目标位置(m为0~n-1).    接下来给出n个数,第i个值对应第i-1个位置的优先级大小.    打印规则如下:    ...

  3. Printer Queue

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

  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. POJ 3481 Double Queue STLmap和set新学到的一点用法

    2013-08-08 POJ 3481  Double Queue 这个题应该是STL里较简单的吧,用平衡二叉树也可以做,但是自己掌握不够- -,开始想用两个优先队列,一个从大到小,一个从小到大,可是 ...

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

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

  8. J - Printer Queue 优先队列与队列

    来源poj3125 The only printer in the computer science students' union is experiencing an extremely heav ...

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

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

随机推荐

  1. Java调用.Net WebService参数为空解决办法 (远程)调试webservice方法 转

    Java调用.Net WebService参数为空解决办法 (远程)调试webservice方法   同事遇到一个很囧的问题,java调,netwebservice的时候,调用无参数方法成功,调用有参 ...

  2. python的一些学习资料(持续更新中)

    Markdown在线编辑器 廖雪峰官方博客[基础入门好资料] python-guide[传说中的巨牛写的] the5fire的技术博客[全职python程序员博客]

  3. laravel队列-让守护进程处理耗时任务

    待解决的问题 最近在做一个服务器集群管理的web项目,需要处理一些极其耗时的操作,比如磁盘格式化分区.对于这个需求,最开始的想法是,为了让节点上的rpc(远程过程调用) service端尽可能简单(简 ...

  4. Python开发之--前端 HTML基础

    一:HTML介绍 HTML:超文本标记语言,标准通用标记语言下的一个应用.包括"头"部分(英语:Head).和"主体"部分(英语:Body),其中"头 ...

  5. c++11的for新用法 (重新练习一下for_each)

    看到手册的代码里面有个for的很奇怪的用法,用了一把    http://www.cplusplus.com/reference/unordered_set/unordered_set/insert/ ...

  6. ssh登录docker容器

    ssh登录docker容器1.启动一个docker容器# docker run -t -i ubuntu/ruby:v1 /bin/bash2.然后在容器里,安装openssh-server open ...

  7. WebApp触屏版网站开发要点

    所谓的触屏版网站其实也是WebApp的一种展示形式,主要是依赖HTML+CSS+Javascript这三个关键因素来实现,相比较原生客户端程序来说优点就是开发周期短.升级简单.维护成本低,因为从根本上 ...

  8. 【POJ 3162】 Walking Race (树形DP-求树上最长路径问题,+单调队列)

    Walking Race   Description flymouse's sister wc is very capable at sports and her favorite event is ...

  9. 2-3 tree使用

    The 2-3 tree is also a search tree like the binary search tree, but this tree tries to solve the pro ...

  10. linux操作Oracle导入导出dmp数据命令

    --清空该表数据 :非索引清空TRUNCATE TABLE  GE_INTERFACE_MESSAGE; --数据库导出 指定导出某个用户的所有数据 包括表 索引 序列 存储过程 函数 等exp CX ...