-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path1996(Deque).java
More file actions
64 lines (53 loc) · 2 KB
/
1996(Deque).java
File metadata and controls
64 lines (53 loc) · 2 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
import java.awt.*;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.*;
public class Main {
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
StringBuilder sb = new StringBuilder();
int T = Integer.parseInt(br.readLine());
while (T --> 0){
StringTokenizer st = new StringTokenizer(br.readLine()," ");
int N = Integer.parseInt(st.nextToken());
int M = Integer.parseInt(st.nextToken()); //찾아야할원소가 처음에 어디위치한지
st = new StringTokenizer(br.readLine()," ");
Deque<Point> q = new LinkedList<Point>();
int find = 0; //찾아야할 원소가 무엇인지(index말고 value)
for(int i = 0; i < N; i++){
int temp = Integer.parseInt(st.nextToken());
if(i == M){//index동일할시 value 저장
find = temp;
}
q.addLast(new Point(temp, i)); //i는 몇번째인지 표기하기 위함
}
//queue에 모든 원소 저장완
int count = 0;
while(true){
boolean checked = false;
if(N == 1){
break;
}
Point a = new Point(q.remove());
int num = a.x;
int index = a.y;
for(Point temp : q){ //전체살피면서 뒤에 더 큰 중요도가있나확인
if(num < temp.x){
checked = true;
}
}
if(checked){
q.addLast(new Point(num, index));
}else{
if(num == find && index == M){
break;
}
count++;
}
}
sb.append(count + 1).append('\n');
}
System.out.println(sb);
}
}