넘치게 채우기

[Codeforces Round 973(Div. 2)] A. Zhan's Blender 본문

PS/Codeforces

[Codeforces Round 973(Div. 2)] A. Zhan's Blender

riveroverflow 2024. 9. 25. 22:15
728x90
반응형

https://codeforces.com/contest/2013/problem/A

Codeforces Round 973(Div. 2) - A. Zhan's Blender

문제 유형 : 구현

 

문제

time limit per test
1 second
memory limit per test
256 megabytes

Today, a club fair was held at "NSPhM". In order to advertise his pastry club, Zhan decided to demonstrate the power of his blender.

To demonstrate the power of his blender, Zhan has 𝑛fruits.

The blender can mix up to 𝑥 fruits per second.

In each second, Zhan can put up to 𝑦 fruits into the blender. After that, the blender will blend min(𝑥,𝑐) fruits, where 𝑐c is the number of fruits inside the blender. After blending, blended fruits are removed from the blender.

Help Zhan determine the minimum amount of time required for Zhan to blend all fruits.

 

오늘, "NSPhM"에서 동아리 박람회가 열렸다.

그의 페이스트리 동아리를 홍보하기 위해, Zhan은 그의 블렌더의 힘을 보여주기로 결심한다.

그의 블렌더의 힘을 보여주기 위해, Zhan은 n개의 과일을 가지고 있다.

초당 x개의 과일을 갈아버릴 수 있다.

각 초마다, Zhan은 y개의 과일을 블렌더에 더 넣을 수 있다. 블렌더는 min(x, c)개를 갈아버릴 수 있는데, c는 블렌더에 있는 과일수이다.

블렌딩이 끝나면, 과일은 블렌더에서 제거된다.

Zhan이 모든 과일을 갈아버리는데 필요한 최소 시간을 구하시오.

 

입력

Each test contains multiple test cases. The first line contains the number of test cases 𝑡t (1≤t≤1000). The description of the test cases follows.

The first line of each test case contains one integer 𝑛 (0𝑛10^9) — the number of fruits Zhan has.

The second line of each test case contains two integers 𝑥 and 𝑦 (1𝑥,𝑦10^9) — the number of fruits the blender can blend per second and the number of fruits Zhan can put into the blender per second.

 

각 테스트는 여러 개의 테스트 케이스를 가진다.

첫째 줄에 테스트 케이스 t가 주어진다. (1 <= t <= 1000).

각 테스트 케이스의 첫 줄은 한 개의 정수 n이 주어진다. (0 <= n <= 10^9). 이는 Zhan이 가진 총 과일의 양이다.

두 번째 줄은 x와 y가 주어진다. (1 <= x, y <= 10^9). 각각 블렌더가 초당 갈아낼 수 있는 과일의 양, 초당 블렌더에 넣을 수 있는 양을 말한다.

 

출력

For each testcase, output a single integer — the minimum number of seconds to blend all fruits.

 

각 테스트케이스별로, 하나의 정수를 출력하라. - 모든 과일을 갈아버리르데 드는 최소시간

 

풀이

매초 min(x, y)개만큼 갈 수 있다.

즉, n/min(x,y)초에다가 나머지가 있을 시 1초를 더 갈면 된다.

 

코드

C++

#include <iostream>
#include <algorithm>

using namespace std;

int solution(int n, int x, int y) {
    int consume = min(x, y);
    return n / consume + ((n % consume) ?  1 : 0);
}

int main() {
    int t;
    cin >> t;

    for (int i = 0; i < t; ++i) {
        int n, x, y;
        cin >> n;
        cin >> x;
        cin >> y;
        cout << solution(n, x, y) << "\n";
    }

    return 0;
}
 
728x90
반응형

'PS > Codeforces' 카테고리의 다른 글

[Codeforces Round 973(Div. 2)] B. Battle for Survive  (0) 2024.09.26