-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy path1443_Printer_Queue.cpp
More file actions
68 lines (65 loc) · 1.91 KB
/
Copy path1443_Printer_Queue.cpp
File metadata and controls
68 lines (65 loc) · 1.91 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
// Problem#: 1443
// Submission#: 1792084
// The source code is licensed under Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported License
// URI: http://creativecommons.org/licenses/by-nc-sa/3.0/
// All Copyright reserved by Informatic Lab of Sun Yat-sen University
#include <iostream>
#include <cstdio>
#include <queue>
#include <cstring>
using namespace std;
int p[101];
queue<int >fuck;
int countf[10];
int maxf;
int main(){
int T;
scanf("%d",&T);
while(T --){
int n,pos;
memset(countf,0,sizeof(countf));
while(!fuck.empty())fuck.pop();
maxf = 0;
scanf("%d%d",&n,&pos);
//cout << maxf << endl;
for(int i = 0;i < n;i ++){
scanf("%d",&p[i]);
if(p[i] > maxf)maxf = p[i];//cout << "fuck" ; cout << p[i] <<endl;}
//cout << maxf << endl;
countf[p[i]] ++;
//cout << "countf++"<<maxf << endl;
fuck.push(i);
//cout << "fuck++" << maxf << endl;
//cout << i << " " << maxf << endl;
}
for(int i = 0;i < n;i ++){
// cout << p[i] << " ";
}
//cout << endl;
int counta = 1;
//cout << maxf << endl;
while(!fuck.empty()){
int tmp = fuck.front();
//cout << maxi << endl;
fuck.pop();
if(p[tmp] == maxf){
if(tmp == pos){
printf("%d\n",counta);
break;
}
else {
countf[p[tmp]] --;
if(countf[p[tmp]] == 0){
int k = p[tmp] -1;
while(countf[k] == 0 && k > 0)k --;
maxf = k;
}
counta ++;
}
}
else {
fuck.push(tmp);
}
}
}
}