题目:

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. CentOS 6.5-默认没开启网络连接:开启网络连接

    vi  /etc/sysconfig/network-scripts/ifcfg-eth0 修改网络, 禁止IP6开启,禁止自启动服务chkconfig

  2. (转载)DBGridEh导出Excel等格式文件

    DBGridEh导出Excel等格式文件 uses DBGridEhImpExp; {--------------------------------------------------------- ...

  3. centos 6.3 64位安装php5.5及配置tengine

    PHP 用到的工具包: yum install gd-devel libjpeg-devel libpng-devel freetype-devel libxml2-devel curl-devel ...

  4. Mvc学习笔记(2)

    Razor模板的具体语法使用 因为Razor模板的可以自动识别<>,大大减少了代码量,本节我们一起来探究Razor模板的语法的简单应用: MVC知识点: 1.ASP.NET Mvc框架 是 ...

  5. PDF转WORD工具 Solid Converter PDF v9.1.6744

    Solid Converter PDF中文破解版(pdf转换成word转换器)是一款功能强大的PDF格式转换软件.Solid Converter PDF允许用户将PDF转换为Word(PDF to W ...

  6. ColorFilter类

    以前没用到过LightingColorFilter这个类 ,google了下 @Override protected void onDraw(Canvas canvas) { int mul = 0x ...

  7. 17.1.4 Replication and Binary Logging Options and Variables 复制和Binary logging 选项和变量

    17.1.4 Replication and Binary Logging Options and Variables 复制和Binary logging 选项和变量 下面的章节包含信息关于mysql ...

  8. 子查询解嵌套not in 无法展开改写

    SQL> explain plan for select * from OPS$CZTEST1.SAVJ_ATOMJOURBAK where ((list_flag = '1' and prt_ ...

  9. 队列的实现(JAVA)

    定义    队列(queue)是一种特殊的线性表,它只允许在表的前端进行删除,在表的后端进行插入. 进行插入端的称为队尾,进行删除端的称为队头.队列是先进先出原则的.队列的实现同样可以 使用两种方式来 ...

  10. C#简单多线程使用(同步和优先权)

    题目: 麦当劳有两个做汉堡的厨师(工号:11,12)和三个销售人员(工号:21,22,23). 厨师生产汉堡,并负责将做好的汉堡放入货架,货架台大小有限,最多放6个汉堡,11和12不能同时往货架台上放 ...