BOJ 1069 집으로

1 개요[ | ]

BOJ 1069 집으로

2 C++[ | ]

#include <bits/stdc++.h>
using namespace std;

int X, Y, D, T;

void solve() {
    double dist = sqrt(X*X + Y*Y);
    double answer = dist;
    int cnt = dist / D;
    dist -= cnt * D;
    if (cnt == 0) {
        answer = fmin(answer, T + D - dist);
        answer = fmin(answer, 2.0 * T);
    } else {
        answer = fmin(answer, cnt * T + dist);
        answer = fmin(answer, (cnt + 1) * T);
    }
    cout << fixed;
    cout.precision(13);
    cout << answer;
}

int main() {
    ios::sync_with_stdio(0);
    cout.tie(0);
    cin >> X >> Y >> D >> T;
    solve();
}
문서 댓글 ({{ doc_comments.length }})
{{ comment.name }} {{ comment.created | snstime }}