문제: https://www.acmicpc.net/problem/1072
앞선 문제들과 같이 이진 탐색으로 쉽게 풀 수 있는 문제입니다.
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 36 37 38 39 40 41 42 43 44 45 46 47 48 49 | #pragma warning (disable:4996) #include <cstdio> #include <cstring> #include <climits> #include <algorithm> using namespace std; typedef long long ll; bool isChanged(int x, int y, ll mid) { ll oldValue = (ll)y * 100 / x; ll newValue = (mid + (ll)y) * 100 / (x + mid); return newValue != oldValue; } int binarySearch(int x, int y) { ll low, high, ret; low = 0; high = ret = x; while (low <= high) { ll mid = (low + high) / 2; if (!isChanged(x, y, mid)) { low = mid + 1; } else { ret = min(ret, mid); high = mid - 1; } } return ret; } int main() { int x, y; while (scanf("%d %d", &x, &y) != EOF) { if ((ll)y * 100 / x >= 99LL) printf("-1\n"); else printf("%d\n", binarySearch(x, y)); } return 0; } | cs |
'Algorithm, Data structure > Solved Algorithmic Problem' 카테고리의 다른 글
BAEKJOON 1992 - 쿼드트리 (0) | 2017.01.05 |
---|---|
BAEKJOON 2792 - LJUBOMORA (0) | 2017.01.05 |
BAEKJOON 3079 - AERODROM (0) | 2017.01.01 |
BAEKJOON 3020 - FIREFLY (0) | 2016.12.31 |
BAEKJOON 2110 - 공유기 설치 (0) | 2016.12.30 |