zoukankan      html  css  js  c++  java
  • 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 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被执行的时间。

    代码如下:^-^
     1 #include<iostream>
     2 #include<stdio.h>
     3 using namespace std;
     4 
     5 int a[120*120],m,n;
     6 
     7 int sousou()
     8 {
     9     int frontt=0,i,maxx,time=0;
    10      while(1)
    11         {
    12             maxx=a[frontt];
    13             for(i=frontt;i<m;i++)
    14                 if(a[i]>maxx)
    15                 {
    16                     if(frontt==n) n=m;
    17                     a[m++]=a[frontt++];
    18                     break;
    19                 }
    20                 else
    21                     if(i==m-1)
    22                 {
    23                     time++;
    24                     if(frontt==n) return time;
    25                     frontt++;
    26                 }
    27         }
    28 }
    
    

    //这道题弄了很久.................结果是等号多打了一个................T T




  • 相关阅读:
    表单全选,不选和反选
    利用js改变宽,高等属性
    点击显示与隐藏
    改变div的不同属性
    给三个不同的div变色
    经典排序算法实现
    基本排序算法的实现
    排序的概念及分类实现
    #和##运算符实例
    #pragma预处理实例
  • 原文地址:https://www.cnblogs.com/teilawll/p/3226800.html
Copyright © 2011-2022 走看看