-
Notifications
You must be signed in to change notification settings - Fork 1
/
Baekjoon1966.java
47 lines (40 loc) · 1.16 KB
/
Baekjoon1966.java
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
package Algorithms;
import java.util.*;
/**
* https://www.acmicpc.net/problem/1966
* 백준 1966 프린터 큐
*/
public class Baekjoon1966 {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int testCase = sc.nextInt();
for (int i = 0; i < testCase; i++) {
int N = sc.nextInt();
int M = sc.nextInt();
int[] priority = new int[N];
for (int j = 0; j < N; j++) {
priority[j] = sc.nextInt();
}
solution(priority, N, M);
}
}
private static void solution(int[] priority, int n, int m) {
Queue<Integer> queue = new LinkedList<>();
for (int i = 0; i < n; i++) {
queue.add(i);
}
int count = 0;
loop1: while(!queue.isEmpty()){
int current = queue.poll();
for(int num : queue){
if(priority[num]>priority[current]){
queue.add(current);
continue loop1;
}
}
count++;
if(current == m) break loop1;
}
System.out.println(count);
}
}