※ 글쓴이는 취미로 코딩을 익혀보는 사람이라 정확하지 않은 내용을 담고 있을 수 있다 ※

 

이번에 볼 문제는 백준 24603번 문제인 Scaling Recipe이다.
문제는 아래 링크를 확인하자.

https://www.acmicpc.net/problem/24603

 

24603번: Scaling Recipe

The first line of input contains three integers $n$ ($1 \le n \le 40$), $x$ and $y$ ($1 \le x,y \le 40{,}000$), where $n$ is the number of ingredients in the recipe, $x$ is the number of portions that the recipe produces, and $y$ is the number of portions

www.acmicpc.net

문제에서 주어지는 비례관계를 이용해 문제를 잘 해결해주자.

 

문제의 답이 정수로 떨어지는 입력만이 주어지므로, 곱할 정수를 모두 곱한 뒤에 나눗셈을 하는 것으로 항상 답을 올바르게 구해낼 수 있다.

 

아래는 제출한 소스코드이다.

#include <iostream>
using namespace std;
typedef long long ll;

ll T, X, Y;

int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);

	cin >> T >> X >> Y;
	while (T--) {
		ll x; cin >> x;
		cout << x * Y / X << '\n';
	}
}
728x90

'BOJ' 카테고리의 다른 글

[BOJ 10693 // C++] Abdelrahman  (0) 2023.01.06
[BOJ 8794 // C++] Poniedziałki  (0) 2023.01.06
[BOJ 9698 // C++] SAHUR & IMSA’  (0) 2023.01.06
[BOJ 24311 // C++] ПЪТУВАНЕ  (0) 2023.01.06
[BOJ 5157 // C++] Bailout Bonus  (0) 2023.01.06

+ Recent posts