[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;
    }
}

相关文章:

  • 2021-07-08
  • 2021-11-09
  • 2021-10-10
  • 2021-07-19
  • 2021-06-06
  • 2021-10-10
  • 2022-01-28
  • 2021-10-19
猜你喜欢
  • 2021-11-26
  • 2021-06-12
  • 2021-11-25
  • 2021-05-15
  • 2021-10-02
  • 2021-06-24
  • 2021-08-27
相关资源
相似解决方案