728x90
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 | import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.IOException; import java.io.InputStreamReader; import java.io.OutputStreamWriter; import java.util.LinkedList; public class Main { private static BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); private static BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out)); public static void main(String[] args) throws IOException{ int T = Integer.parseInt(br.readLine()); for(int i=0; i<T; i++) { String[] arr = br.readLine().split(" "); int N = Integer.parseInt(arr[0]); int M = Integer.parseInt(arr[1]); LinkedList<int[]> list = new LinkedList<>(); String[] strArr = br.readLine().split(" "); for(int j=0; j<N; j++) { list.add(new int[] {j, Integer.parseInt(strArr[j])}); } int res = 0; Loop1: while(!list.isEmpty()) { int[] pre = list.peekFirst(); for(int j=1; j<list.size(); j++) { if(pre[1]<list.get(j)[1]) { list.add(list.pollFirst()); continue Loop1; } } int[] out = list.pollFirst(); res++; if(out[0]==M) { System.out.println(res); break; } } // System.out.println(N); // System.out.println(M); } // bw.write(sBuilder.toString()); bw.flush(); bw.close(); } } | cs |
'알고리즘 풀이 > 백준' 카테고리의 다른 글
[백준][Java] 1080번 행렬 (그리디) (0) | 2021.09.11 |
---|---|
★ [백준][Java] 2504번 괄호의 값(Stack) #2 (0) | 2021.09.11 |
[백준][Java] 5430번 AC (String, Deque) (0) | 2021.09.09 |
[백준][Java] 1032번 명령 프롬프트 (String) (0) | 2021.09.09 |
[백준][Java] 4949번 균형잡힌 세상 (String, stack) (0) | 2021.09.08 |