1443. Printer Queue
来源:互联网 发布:ppt图表如何修改数据 编辑:程序博客网 时间:2024/06/08 07:11
注:c++实验课堂题目
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
// 用vector实现// 注意善用node使得数组能够存储多个信息,这些信息其实包含在node中#include<iostream>#include<vector>using namespace std;struct node { int index; int priority; node(int i = 0, int p = 0):index(i), priority(p) {};};int main() { int t; cin >> t; while (t--) { vector<node> que; int alljob, myjob; cin >> alljob >> myjob; int temp; for (int i = 0; i < alljob; ++i) { cin >> temp; que.push_back(node(i, temp)); } int result = 0; while (!que.empty()) { node top = que.front(); bool flag = false; for (int i = 1; i < que.size(); ++i) { if (que[i].priority > que[0].priority) { que.push_back(top); flag = true; break; } } que.erase(que.begin()); if (flag == false) result++; if (flag == false && top.index == myjob) break; } cout << result << endl; } return 0;}
- 1443. Printer Queue
- sicily--1443. Printer Queue
- Sicily 1443. Printer Queue
- 1443. Printer Queue
- 1443. Printer Queue
- sicily 1443.Printer Queue
- sicily 1443. Printer Queue
- Sicily 1443. Printer Queue
- sicily 1443.Printer Queue
- 1443. Printer Queue
- Sicily 1443. Printer Queue
- sicily 1443. Printer Queue
- [sicily]1443. Printer Queue
- 1443. Printer Queue
- 1443. Printer Queue
- sicily-1443. Printer Queue
- Sicily 1443. Printer Queue
- Sicily 1443.Printer Queue
- 最常用--正则表达式列表
- Android之数据库—— 一个可配置的简易框架
- Erlang调度器的一些细节以及它重要的原因(译文)
- 文章标题
- poj3253
- 1443. Printer Queue
- 自定义view
- LeetCode:Sum of Two Integers
- ubuntu14.04 php nginx mysql redis phpmyadmin
- eclipse各个版本介绍(转)
- 设计模式-观察者模式
- Navicat For Mysql快捷键
- 一位软件工程师的6年总结
- (JDBC复习二)获取链接后操作数据库,增删检查