PS

BOJ 1980 : 햄버거 사랑

lickelon 2025. 2. 17. 22:15

코드

#include <bits/stdc++.h>

#define all(x) (x).begin(), (x).end()

#define INF 0x7FFFFFFF

using namespace std;

using ll = long long;
using ld = long double;
using pii = pair<int,int>;
using pll = pair<ll, ll>;

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

    int n, m, t;
    cin >> n >> m >> t;

    pii ans = {0, INF};
    for(int i = 0; i*n <= t; i++) {
        int l = t-i*n;
        int j = l/m;
        int k = l % m;
        if(ans.second > k) {
            ans = {i+j, k};
        }
        else if(ans.second == k) {
            ans.first = max(ans.first, i+j);
        }
    }
    cout << ans.first << " " << ans.second;

    return 0;
}

풀이

한 햄버거를 먹는 개수가 정해지면 최적의 경우에 대해 다른 햄버거를 먹는 개수와 콜라를 마시는 시간이 정해진다.

따라서 어떤 햄버거를 먹는 개수를 변수로 하여 브루트포스를 수행하면 답을 구할 수 있다.

 

728x90

'PS' 카테고리의 다른 글

BOJ 6616 : 문자열 암호화  (1) 2025.02.20
BOJ 9324 : 진짜 메시지  (0) 2025.02.19
BOJ 2090 : 조화평균  (1) 2025.02.16
BOJ 2312 : 수 복원하기  (0) 2025.02.15
BOJ 7585 : Brackets  (0) 2025.02.14