POJ 3125 Printer Queue(打印队列---模拟)

Printer Queue(打印队列)POJ3125 Printer Queue Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 2817   Accepted: 1523 Description 阅读详情

题目链接: http://poj.org/problem?id=3125

 

Printer Queue
Time Limit: 1000MS Memory Limit: 65536K
Total Submissions: 3082 Accepted: 1655

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

Source

/*
思路(yf):
这个题思路很简单,就是运用的队列,主要是处理时费时间。要想清楚才行,
比如说,第一个,从队列的front 看来是找到rear,如是没有比他大的就直接打印,time +=1;
判断这个点是不是标记的那个点,如果是,则直接输出time ,如果不是就向后走,
还有需要注意的就是,如果是找到那个要打印的那个点,如果不能打印,
那么这个标记打印的数也要跟着变化,
主要就这两点吧
代码:
*/

#include<iostream>
#include<stdio.h>
using namespace std;
int main()
{
	int a[10010];
	int front,rear,i;
	int cases,n,d,time,ok;
	scanf("%d",&cases);
	while(cases--)
	{
		front=0;rear=0;time=0;ok=0;
		scanf("%d%d",&n,&d);
		for(i=0;i<n;i++)
		{
			scanf("%d",&a[i]);
			rear++;
		}
		while(front<=rear)
		{
			for(i=front;i<rear;i++)
			{
				if(a[i]>a[front]) 
				{
					a[rear++]=a[front];
					break;
				}
			}
			
			if(i>=rear) 
			{
				time+=1;
				if(front==d)
				{
					printf("%d\n",time);
					ok=1;
					break;
				}
				else 
					front++;
			}
			else if(front==d) {d=rear-1;} 
			else front++;
			if(ok) break;
		}
	}
	return 0;
}


【C#】清空电脑打印机的队列 C# 清空电脑打印机的队列 利用程序实现 取消所有文档,如下图: 第一步,先引用命名空间 using System.Management; using System.Printing; 如果using System.Printing;报错,选中项目,右键单击,选择添加引用 第二步,编写代码 核心代码如下,PrintQueue pq = localPrintServer.GetPrintQueue(“PT561”); 指定要清空打印机的名称 private void clearPr 阅读详情

相关推荐

Java写项目前的准备工作指南(技术栈选择 环境搭建和工具配置 项目结构设计与模块划分)

在开始编写一个 Java 项目之前,做好充分的准备工作是至关重要的。很多初学者可能在没有清晰规划的情况下就开始编写代码,导致项目开发进度缓慢、结构混乱,甚至最终无法按预期完成。而事实上,项目的成功不仅仅取决于编码能力,还包括项目初期的规划和准备。准备工作是确保项目顺利进行的基础,它包括技术选型、环境搭建、需求分析、团队协作及项目管理等多个方面。通过这些准备,我们可以确保项目的开发不仅高效而且有可维护性,最终能交付出高质量的代码。在项目开发过程中,异常处理是非常关键的一部分。

eternal__day的博客 1188

关于移动硬盘插入后无显示的问题

移动硬盘插入不显示问题解决

m0_53731235的博客 6831

从业10年的AI应用架构师:企业AI平台运营的4个核心经验,值得收藏

去年年底,我在某大型制造企业做AI咨询时,遇到了这样的场景:这不是个例。我接触过的10家企业中,有7家的AI平台都陷入了“技术自嗨”的陷阱——技术团队追求模型精度、功能完备性,却忽略了业务到底需要什么。如果你也遇到过类似问题:比如“模型准确率很高,但业务不买账”“AI项目上线后没人用”“投入产出比极低”,那么这篇文章的4个经验,可能会帮你避开这些坑。很多企业认为,AI平台就是“买一套工具+部署几个模型”。但实际上,企业AI平台的本质是“技术与业务的连接生态”:根据Gartner的报告,80%的企业AI项目失

AI 原生应用开发的博客 709

Win10打印功能(组件)恢复(修复)

一、 注册表1、控制及类pe-sys\ControlSet001\Control\Printpe-sys\ControlSet001\Control\Class\{1ed2bbf9-11f0-4084-b21f-ad83a8e6dcdc}pe-sys\ControlSet001\Control\Class\{4658ee7e-f050-11d1-b6bd-00c04fa372a7}pe-sys\ControlSet001\Control\Class\{49ce6ac8-6f86-11d2-b1e5-0080

我的博客 8817

保姆级教程:手把手调试PX4Ctrl的油门映射与姿态控制(附ROS节点配置)

本文提供PX4Ctrl的深度调参指南,涵盖油门映射、姿态控制及ROS节点配置等关键环节。通过详细解析PX4控制器的核心逻辑、递归最小二乘法(RLS)参数估计及状态机设计,帮助开发者优化无人机飞控性能。附实战案例与安全调试建议,适合PX4开发者进阶学习。

weixin_30363981的博客 382

宇树GO2-YOLOv5在Jetson Orin上的部署避坑实践

本文详细记录了在宇树GO2四足机器人搭载的Jetson Orin平台上部署YOLOv5目标检测模型的完整实践过程。文章重点分享了从ARM架构认知、网络连接解决方案、Archiconda环境搭建、PyTorch版本精准匹配到依赖安装与性能验证的核心步骤与避坑指南,旨在帮助开发者高效完成边缘计算环境下的算法部署。

app77的博客 669

USB鼠标无法正常连接电脑

USB鼠标无法正常连接电脑 驱动设置安装、进程服务检查、系统电源节能默认设置、第三方驱动软件使用; Win10禁用驱动程序强制签名;

weichenyang的博客 5910

汽车TARA分析实战:从威胁建模到安全需求落地的完整指南

在汽车电子电气系统开发中,威胁分析与风险评估(TARA)是确保功能安全与网络安全的核心方法论。其原理在于通过结构化的流程,系统性地识别资产、分析威胁场景并评估风险,旨在将安全理念前置,从设计源头规避风险。这一过程的技术价值在于将模糊的安全担忧转化为可量化、可追溯的工程需求,从而指导资源精准投放,是符合ISO 26262和ISO/SAE 21434标准要求的关键实践。其应用场景贯穿智能汽车从概念设计到系统开发的各个阶段,尤其对于涉及自动驾驶、智能座舱、车云通信等复杂功能的域控制器开发至关重要。本文聚焦于TAR

weixin_42706667的博客 303

POJ 3125 Printer Queue【简单模拟a打印队列】

经典的模拟队列题目 题目链接: http://poj.org/problem?id=3125 2012年8月7日,暑假组队后个人训练赛第一场 Printer Queue Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 3082   Accepted: 1655

free斩 2487

RPMsg:协议简介

两台计算机可以通过TCP/IP进行通信,那么同一颗芯片上的两个核心怎么通信呢?

SunnyZhou-1024的博客 1万+

基于轻量化网络的干扰信号智能识别算法

针对干扰信号识别时卷积神经网络模型体积大、训练周期长、对硬件存储和计算要求高等问题,本 文提出了一种基于改进轻量级网络模型 SqueezeNet 的干扰信号智能识别算法。该方法首先利用距离多普勒 (Range‑Doppler,RD)处理获得目标及干扰信号的RD图像,接着采用滑窗变换、归一化等技术对RD图像进行重 塑;然后采用基于 RD 信息尺寸的隐层和通道剪枝措施对 SqueezeNet 网络进行改进,缩小了模型尺寸和存储空 间;最后利用不同参数的测试样本拓展网络模型的泛化性能。

qq_43416206的博客 544

Printer Queue算法(华为: 打印任务排序, POJ3125)Golang实现

问题描述 Printer Queue(打印队列)POJ3125 打印机顺序打印问题 这是一道ACM算法题,上面的两个是求打印时间,还有一种是求打印顺序 输入和输出: 输入 3 1 0 5 4 2 1 2 3 4 6 0 1 1 9 1 1 1 输出 1 2 5 问题解析 输入解析 第一行的: 3 3个测试用例,每个测试用例包含两行,所以下面有6行,以最后一个用例为例解析 倒数第二行6 0...

cumt_TTR的专栏 3336

华为OD机试真题 新系统2026-04-01 Python&JS 实现【空间占用计算】

员工A的磁盘空间经常被耗尽,他需要找到占用空间最大的目录或文件,然后决定如何清理文件释放空间。给定某一目录,请编写程序帮助他统计该目录内一级子目录和文件的占用空间,并返回目标目录一级子项(文件或子目录)中占用空间最大的项。

MISAYAONE的博客 1298

Printer Queue(poj3125模拟队列)

/*http://acm.hust.edu.cn/vjudge/contest/view.action?cid=27454#problem/A http://poj.org/problem?id=3125 Printer Queue Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 3337 Accepted: 1813

JHC23的专栏 861

IDEA的使用指南

IDEA基于java的使用手册,可以最快速的上手,在使用中不断的丰富自己的使用技巧.

efm32 入门.pdf

本PDF共计22页,介绍的是操作驱动API,下载与否自己斟酌。

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...

dianxuanzhi1019的博客 685

Probability and Statistics - 4th edition

Probability and Statistics - 4th edition

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 fo

菜鸟起飞的平台 417

pscad IEEE标准系统搭建说明

pscad IEEE标准系统搭建说明,包含典型的IEEE 9节点、14节点、30节点、39节点和118节点系统。内含标准测试系统的原始数据和潮流结果。

POJ3125 printer(队列的使用)

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 wai

ChenYitian 483

POJ3125 Printer Queue

//5_3_3: Printer Queue 打印机优先队列问题 POJ3125 #include #include #include using namespace std; const int maxn = 100 + 5; int main() { int i,n,m,k,a[maxn],cnt,tag,head,rear,loop,print; scanf("%d",&loop)

244

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

/* * POJ_3125.cpp * * Created on: 2013年10月31日 * Author: Administrator */ #include #include #include using namespace std; int main() { int t; scanf("%d", &t); while (t--) { queue

黄俊东的专栏 1693

POJ 3125 Printer Queue(用队列模拟过程)

题目链接:http://poj.org/problem?id=3125Printer Queue Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 5001 Accepted: 2600 DescriptionThe only printer in the computer science students’

linlinsong—ACM界蒟水! 763

queue队列-printer queue

queue和栈差不多就是普通操作有一些不一样; stack: push()入栈 top()出栈一个元素不删除-出栈元素为最后一个入栈元素 pop()出栈,删除 empty()判断非不非空 queue: push()入队 front()取队列第一个入队的并不删除 pop()出队,删除 empty()判断非不非空 priority: 同队列操作一样只不过 出队front()——

DeathYmz的博客 627

POJ3125--Printer_Queue

题目链接:http://poj.org/problem?id=3125      题目大家读一下意思很容易理解,在此就不赘述。本题主要就是考察单链表/队列的简单操作。 算法设计: 1.根据输入创建队列CreateList()函数,然后用addNode()函数向队列上增加结点,那么得到队列; 结点定义为: typedef struct LNode {     int pri

懂幸福,爱生活 911

9.1 poj3125 Printer Queue

题目链接:http://poj.org/problem?id=3125题意:给出一串打印的优先级,如果打印当前点i但是后面有比他优先级高的,那么将i点放到最后。如果后面没有比当前点优先级高的,则打印。已知打印耗时1,移动是瞬时完成的。求打印p时的时间。思路:使用队列queue模拟,直接按照题意进行模拟。#include&lt;cstdio&gt; #include&lt;cstring&gt; #...

qq_35710556的博客 185

poj 3125 Printer Queue (队列)

 Printer Queue Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 3679   Accepted: 1975 Description The only printer in the computer science students' union is

Just do it ! 2793

POJ - 3125 Printer Queue(优先队列)

POJ - 3125 Printer Queue(优先队列) #include<iostream> #include<queue> using namespace std; typedef pair<int,int> PII; const int N = 100; PII a[N]; int main() { int T;cin>>T; while(T--) { int n,m;cin>>n>>m; queue<P

00后的博客 362

POJ 3125 && Sicily 1443 Printer Queue(模拟/队列)

//简单的队列模拟#include#include#include#includeusing namespace std;int priority[101];struct Job{ int priority; bool yours;}job[101];bool cmp(int a,int b){ return a > b;}int m

Czy 1891
上一篇: poj1753Flip Game
下一篇: POJ 1840 Eqs(简单hash入门)
CSUST_ACM
博客等级 码龄15年 42粉丝 127原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值