728x90
https://www.acmicpc.net/problem/1072
메모리: 11,516 KB , 시간: 72 ms
사용 알고리즘: 이분 탐색
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.StringTokenizer;
public class Main {
public static void main(String[] args) throws Exception{
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
StringTokenizer st = new StringTokenizer(br.readLine());
int x = Integer.parseInt(st.nextToken());
int y = Integer.parseInt(st.nextToken());
int z = (int)(((long)y * 100) / x);
if(x == y) {
System.out.println(-1);
return;
}
// 이분탐색
int s = 1, e = x, m;
int answer = -1;
while(s <= e) {
m = (s + e) / 2;
if(z < (int)(((long)(y + m) * 100) / (x + m))) {
e = m - 1;
answer = m;
}
else s = m + 1;
}
System.out.println(answer);
}
}728x90
'Problem Solving > BOJ' 카테고리의 다른 글
| [백준, BOJ 2166] 다각형의 면적 (java) (0) | 2025.12.10 |
|---|---|
| [백준, BOJ 16967] 배열 복원하기 (java) (0) | 2025.12.09 |
| [백준, BOJ 13302] 리조트 (java) (0) | 2025.07.26 |
| [백준, BOJ 2661] 좋은수열 (java) (0) | 2025.07.02 |
| [백준, BOJ 2661] 좋은수열 (java) (0) | 2025.06.24 |