codeforces 1872 c

更新一个签到,主要当时卡了一阵,竟然想到写个函数循环了,实在太麻烦了,遂写一篇题解巩固一下

思路

考虑每个障碍对最终答案做出的贡献,显然每个障碍允许最多从这个点多走(a+(s-1)/2)的距离,手玩一下即得,所以做法就是筛选n个障碍的贡献

ACcode

#include

using namespace std;

using ll = long long;

void solve()
{
    int n;cin >> n;
    int ans = 1e9;
    for (int i = 1;i <= n;i++) {
        int a, b;cin >> a >> b;
        b--;
        ans = min(ans, a + b / 2);
    }
    cout << ans << '\n';
}

int main()
{
    ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    int t;cin >> t;
    while (t--)
    {
        solve();
    }
    return 0;
}

你可能感兴趣的:(c++,算法)