关于“打印队列 Printer Queue, ACM/ICPC NWERC 2006, UVa 12100)"的讨论

打印队列有两个属性,一个是优先级一个是位置,可以写一个结构体存储这些信息再利用queue的特性完成本题

#include<iostream>
#include<queue>
#include<vector>
using namespace std;
const int maxn = 100;
struct Coor
{
	int priority;
	int position;
} co[maxn];
queue<Coor> line;
void main()
{
	int n;
	int a;
	cin >> n;
	for(int i = 0; i < n; i++)
	{
		cin >> a;
		co[i].priority = a;
		co[i].position = i;
		line.push(co[i]);
	}
	int positon;
	cin >> positon;
	int max = 0;
	bool is_print = false;
	int count = 0;
	while(!is_print)
	{
		if(max == 0)
		{
			for(int i = 0; i < n; i++)
			{
				if(co[i].priority != 0)
				{
					if(max < co[i].priority) max = co[i].priority;
				}
			}
		}
		Coor co1 = line.front();
		if(co1.priority == max)
		{
			if(co1.position == positon)
			{
				count++;
				is_print = true;
			}
			else
			{
				co[co1.position].priority = 0;
				max = 0;
				line.pop();
				count++;
			}
		}
		else
		{
			line.pop();
			line.push(co1);
		}		
	}

	cout << count << endl;
}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值