๋ฌธ์
https://www.acmicpc.net/problem/1966
ํ์ด
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Collections;
import java.util.LinkedList;
import java.util.Queue;
import java.util.StringTokenizer;
public class ํ๋ฆฐํฐํ {
static int t; // ํ
์คํธ ์ผ์ด์ค ์
static int n; // ๋ฌธ์์ ๊ฐ์
static int m; // ๊ถ๊ธํ ๋ฌธ์์ ์ด๊ธฐ ์์น
static Queue<Integer> queue; // ๋ฌธ์์ ์ค์๋
static Queue<Integer> indexQueue; // ๋ฌธ์์ ์ธ๋ฑ์ค
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
int t = Integer.parseInt(br.readLine());
for(int i=0; i<t; i++){
StringTokenizer st = new StringTokenizer(br.readLine());
n = Integer.parseInt(st.nextToken());
m = Integer.parseInt(st.nextToken());
queue = new LinkedList<>();
indexQueue = new LinkedList<>();
st = new StringTokenizer(br.readLine());
for(int j=0; j<n; j++){
queue.offer(Integer.parseInt(st.nextToken()));
indexQueue.offer(j);
}
solve();
}
}
public static void solve(){
int count = 1;
while (!queue.isEmpty()) {
int max = Collections.max(queue);
int cur = queue.poll();
int curIndex = indexQueue.poll();
if(cur == max){
if (curIndex == m) {
System.out.println(count);
break;
}
count++;
}
else{
queue.offer(cur);
indexQueue.offer(curIndex);
}
}
}
}
'๐๏ธ Algorithm > ๐ฉ ๋ฐฑ์ค' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
๐ฉ [๋ฐฑ์ค] [Java] [Silver3] 14501๋ฒ_ํด์ฌ (0) | 2024.04.05 |
---|---|
๐ฉ [๋ฐฑ์ค] [Java] [Silver2] 1874๋ฒ_์คํ ์์ด (0) | 2024.01.13 |
๐ฉ [๋ฐฑ์ค] [Java] [Silver4] 10866_๋ฑ (1) | 2024.01.10 |
๐ฉ [๋ฐฑ์ค] [Java] [Silver2] 1260๋ฒ_DFS์ BFS (0) | 2024.01.08 |
๐ฉ [๋ฐฑ์ค] [Java] [Silver5] 2941๋ฒ_ํฌ๋ก์ํฐ์ ์ํ๋ฒณ (0) | 2023.12.10 |