안녕하세요. 오늘은 택배를 기다릴 거예요.

문제

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

아이디어

하루에 최대 배달할 수 있는 택배의 수를 day라고 합시다. day=(일하는 전체 시간 -1)/T입니다.
걸리는 일 수는 N/day이고 N/day일 후에 배달되는 시각은 시작시각 + (N%day+1)*T분 후 입니다.

소스코드

#include <iostream>
#include <string>
#define ll long long
using namespace std;

ll diff(ll startH, ll startM, ll endH, ll endM)
{
    return (endH - startH) * 60 + (endM - startM);
}
void PLUS(ll H, ll M, ll plus)
{
    M += plus;
    if (M >= 60)
    {
        H += M / 60;
        M %= 60;
    }
    if (H >= 24) H %= 24;

    if (H < 10) cout << 0;
    cout << H << ':';
    if (M < 10) cout << 0;
    cout << M;
}

int main(void)
{
    ios_base::sync_with_stdio(false); cin.tie(NULL);
    ll startH, startM, endH, endM;
    char c;

    cin >> startH >> c >> startM >> endH >> c >> endM;
    ll tot = diff(startH, startM, endH, endM), N, T;
    cin >> N >> T;

    ll day = (tot - 1) / T;
    cout << N / day << "\n";
    PLUS(startH, startM, (N % day + 1) * T);
}


감사합니다.

0개의 댓글