algorithm/BOJ
BOJ 1072번 게임
_JunHo
2020. 2. 5. 22:43
BOJ : https://www.acmicpc.net/problem/1072
** 현재승률이 99%라면 100%가 될 수 없습니다.
** 무작정 +1 씩해가면서 탐색하게 되면 무조건 TLE에 걸리게 됩니다.
** 이분탐색을 이용해서 해결합니다.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
|
#include <iostream>
#include <math.h>
using namespace std;
int main() {
long long X, Y;;
cin >> X >> Y;
int z = Y * 100 / X;
if (z >= 99) {
cout << "-1";
exit(0);
}
int low = 0, high = 1000000000;
int result = -1;
while (low <= high){
int mid = (low + high) / 2;
int tempz = (100 * (Y + mid)) / (X + mid);
if (z >= tempz)
{
result = mid + 1;
low = mid + 1;
}
else
high = mid - 1;
}
cout << result;
return 0;
}
http://colorscripter.com/info#e" target="_blank" style="color:#e5e5e5text-decoration:none">Colored by Color Scripter
|