A.Two Rival Students

Title: two competing student

Link :( two competing rivals) [ https://codeforces.com/contest/1257/problem/A ]

Meaning of the questions: There are n students in a row. There are two competing students. A student first position a, the second student from left to right from 1 to n number in the position b, position.

Your purpose is to exchange after x number of times, the maximum distance between them. (Two each exchange student exchange are adjacent)

Analysis:
1. The answer is not be greater than n - 1 is
the distance between the two 2 x may be increased by the exchange, so long as the answer is less than n - 1

Therefore, the minimum value whichever is the answer

#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>

using namespace std;
const int INF = 0x3f3f3f3f;
int main()
{
    int t;
    scanf("%d", &t);
    int n, x, a, b;
    while (t--)
    {
        scanf("%d%d%d%d", &n, &x, &a, &b);

        int ans = INF;
        ans = min(n - 1, abs(a - b) + x);
        printf("%d\n", ans);
    }

    return 0;
}

Guess you like

Origin www.cnblogs.com/pixel-Teee/p/11961265.html