• 문제 링크
11968번: High Card Wins
Bessie the cow is a huge fan of card games, which is quite surprising, given her lack of opposable thumbs. Unfortunately, none of the other cows in the herd are good opponents. They are so bad, in fact, that they always play in a completely predictable fas
www.acmicpc.net
• 풀이 코드
import java.io.BufferedWriter;
import java.io.IOException;
import java.io.OutputStreamWriter;
import java.util.ArrayList;
import java.util.List;
public class Main {
public static void main(String[] args) throws IOException {
BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));
int n = read(), m = n * 2;
boolean[] arr = new boolean[m + 1];
for (int i = 0; i < n; i++) arr[read()] = true;
List<Integer> E = new ArrayList<>(), B = new ArrayList<>();
for (int i = 1; i <= m; i++) {
if (arr[i]) E.add(i);
else B.add(i);
}
int e = 0, b = 0, cnt = 0;
do {
if (E.get(e++) < B.get(b++)) cnt++;
else e--;
} while (e < n && b < n);
bw.write(String.valueOf(cnt));
bw.flush();
}
private static int read() throws IOException {
int c, n = System.in.read() & 15;
while ((c = System.in.read()) > 32) n = (n << 3) + (n << 1) + (c & 15);
return n;
}
}
'Problem Solving > Baekjoon' 카테고리의 다른 글
[백준] 14697 방 배정하기 - Brute Force / Java (0) | 2023.12.24 |
---|---|
[백준] 30019 강의실 예약 시스템 - Greedy / Java (0) | 2023.12.23 |
[백준] 16406 Exam - Greedy / Java (0) | 2023.12.21 |
[백준] 20974 Even More Odd Photos - Greedy / Java (0) | 2023.12.20 |
[백준] 15761 Lemonade Line - Greedy / Java (0) | 2023.12.19 |
댓글