• 문제 링크
1072번: 게임
김형택은 지금 몰래 Spider Solitaire(스파이더 카드놀이)를 하고 있다. 형택이는 이 게임을 이길 때도 있었지만, 질 때도 있었다. 누군가의 시선이 느껴진 형택이는 게임을 중단하고 코딩을 하기 시
www.acmicpc.net
• 풀이 코드
import java.io.BufferedWriter;
import java.io.IOException;
import java.io.OutputStreamWriter;
public class Main {
public static void main(String[] args) throws IOException {
BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));
int x = read(), y = read();
long z = y * 100L / x;
if (z < 99) {
int low = 1, high = x;
while (low <= high) {
int mid = (low + high) / 2;
if (z < 100L * (y + mid) / (x + mid)) high = mid - 1;
else low = mid + 1;
}
bw.write(String.valueOf(low));
} else bw.write("-1");
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' 카테고리의 다른 글
[백준] 13702 이상한 술집 - BinarySearch / Java (0) | 2023.08.10 |
---|---|
[백준] 18265 MooBuzz - BinarySearch / Java (0) | 2023.08.09 |
[백준] 15092 Sheba’s Amoebas - Graph Theory / Java (0) | 2023.08.07 |
[백준] 14397 해변 - Graph Theory / Java (0) | 2023.08.06 |
[백준] 27737 버섯 농장 - Graph Theory / Java (0) | 2023.08.05 |
댓글