#include<iostream>
#include<vector>
#include<string>
#include<queue>
#include<set>
#include<algorithm>
using namespace std;
typedef struct Job
{
int pr;
bool flag;
}Job;
int main()
{
int T;cin >> T;
while (T--)
{
queue<Job> q;
priority_queue<int> pq;
int n, m;cin >> n >> m;
for(int i=0;i<n;i++)
{
int p;cin >> p;
Job j = { p,i==m? true :false };
q.push(j);pq.push(p);
}
int time = 0;
while (true)
{
Job J = q.front();q.pop();
if (J.pr != pq.top())
{
q.push(J);
}
else
{
time++;
pq.pop();
if (J.flag)break;
}
}
cout << time << endl;
}
return 0;
}队首的位置是0比较麻烦,所以用了结构体,在里面加了个flag用来标记我们关注的是哪一个任务。然后跟着题意模拟就行了
优先队列是方便判断优先级的。
优先队列模拟打印任务
本文介绍了一个使用C++实现的模拟打印任务处理过程的程序。该程序利用优先队列来跟踪并处理一系列打印任务,确保高优先级的任务能够被优先处理。通过一个结构体来标记特定任务的状态,并在每轮迭代中更新处理进度,直至找到目标任务。
1938

被折叠的 条评论
为什么被折叠?



