알고리즘/BOJ

백준 4623번 Copier Reduction

꾸준함. 2021. 5. 16. 01:38

문제 링크입니다: https://www.acmicpc.net/problem/4623

 

4623번: Copier Reduction

The input consists of one or more test cases, each of which is a single line containing four positive integers A, B, C, and D, separated by a space, representing an AxBmm image and a CxDmm piece of paper. All inputs will be less than one thousand. Followin

www.acmicpc.net

최소 퍼센티지는 1, 최대 퍼센티지는 100이기 때문에 이분탐색을 통해 해결한 문제였습니다.

 

#include <iostream>
#include <algorithm>
using namespace std;
int main(void)
{
ios_base::sync_with_stdio(0);
cin.tie(0);
while (1)
{
int A, B, C, D;
cin >> A >> B >> C >> D;
if (A == 0 && B == 0 && C == 0 && D == 0)
{
break;
}
if (A < B)
{
swap(A, B);
}
if (C < D)
{
swap(C, D);
}
int start = 1, end = 100;
int result;
while (start <= end)
{
int mid = (start + end) / 2;
if (A * mid <= C * 100
&& B * mid <= D * 100)
{
start = mid + 1;
result = mid;
}
else
{
end = mid - 1;
}
}
cout << result << "%\n";
}
return 0;
}
view raw .cpp hosted with ❤ by GitHub

 

개발환경:Visual Studio 2017

 

지적, 조언, 질문 환영입니다! 댓글 남겨주세요~

반응형

'알고리즘 > BOJ' 카테고리의 다른 글

백준 4655번 Hangover  (0) 2021.05.16
백준 4635번 Speed Limit  (0) 2021.05.16
백준 4619번 루트  (0) 2021.05.15
백준 4504번 배수 찾기  (0) 2021.05.15
백준 4493번 가위 바위 보?  (0) 2021.05.15