[CF1492A] Three swimmers

[CF1492A] Three swimmers

Description

三个人在游泳,第 (0) 分钟这三个人人在游泳池的左侧,之后他们开始来回游,游一个来回分别需要 (a,b,c) 分钟。

你在第 (p) 分钟到达游泳池的左侧,请问最少经过多少分钟,你看见一个人在游泳池的左侧?

Solution

把每个人到在 (p) 之后第壹次到达左侧的时间求出来,取个 min 就好了

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

#define int long long

signed main()
{
    ios::sync_with_stdio(false);

    int t;
    cin >> t;

    while (t--)
    {
        int p, a, b, c;
        cin >> p >> a >> b >> c;
        int x = (p + a - 1) / a * a;
        int y = (p + b - 1) / b * b;
        int z = (p + c - 1) / c * c;
        cout << min(x, min(y, z)) - p << endl;
    }
}
原文地址:https://www.cnblogs.com/mollnn/p/14453766.html