๐ ์ ์ถ
import java.util.LinkedList;
import java.util.Queue;
import java.util.Scanner;
public class Main {
public static void main(String[] args){
Scanner sc = new Scanner(System.in);
int tc = sc.nextInt();
for (int i = 0; i < tc; i++) {
int numberOfDocument = sc.nextInt();
int target = sc.nextInt();
Queue<Integer> document = new LinkedList<>();
for (int j = 0; j < numberOfDocument; j++) {
document.add(j);
}
Queue<Integer> priority = new LinkedList<>();
for (int j = 0; j < numberOfDocument; j++) {
priority.add(sc.nextInt());
}
int cnt = 1;
while (!document.isEmpty()) {
int currentDoc = document.remove();
int currentPri = priority.remove();
boolean isMaxValue = true;
for (Integer nextPri : priority) {
if (currentPri < nextPri) {
isMaxValue = false;
}
}
if (isMaxValue) {
if (currentDoc == target) {
System.out.println(cnt);
break;
}
cnt++;
}else {
document.add(currentDoc);
priority.add(currentPri);
}
}
}
}
}
โ ํ์ด
๋ฌธ์์ ์ค์๋๋ฅผ ๊ด๋ฆฌํ๋ ํ๋ฅผ ์ ์ธํ ํ, ๊ฐ ๋ฌธ์์ ์ค์๋๋ฅผ ํ์ธํ๋ฉด์ ํ์ฌ ๋ฌธ์๋ณด๋ค ๋์ ์ค์๋๋ฅผ ๊ฐ์ง ๋ฌธ์๊ฐ ์์ ๊ฒฝ์ฐ ํด๋น ๋ฌธ์๋ฅผ ํ์ ๋ค๋ก ๋ณด๋ด๊ณ , ๊ทธ๋ ์ง ์์ ๊ฒฝ์ฐ ์นด์ดํธ๋ฅผ ์ฆ๊ฐ์ํค๋ ๋ฐฉ์์ผ๋ก ๋ฌธ์ ๋ฅผ ํด๊ฒฐํ์์ต๋๋ค.
'PS > ๋ฐฑ์ค' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
[๋ฐฑ์ค | 15630] N๊ณผ M(2) - Java (0) | 2024.08.14 |
---|---|
[๋ฐฑ์ค | 15649] N๊ณผ M(1) - Java (0) | 2024.08.14 |
[๋ฐฑ์ค | 1158] ์์ธํธ์ค ๋ฌธ์ - Java (0) | 2024.08.10 |
[๋ฐฑ์ค | 10867] ์ค๋ณต ๋บด๊ณ ์ ๋ ฌํ๊ธฐ- Java (0) | 2024.08.09 |
[๋ฐฑ์ค | 1026] ๋ณด๋ฌผ - Java (0) | 2024.08.09 |