CodeForces-1278B-A-and-B

The meaning of problems

For (t (1 \ leq t \ leq 100) \) \ test points, to two numbers \ (A \) and \ (B \) , as follows:

The first pick it plus a number \ (1 \) , so that the second number plus a pick \ (2 \) , and so on, the last two numbers are equal, the minimum number of Q operations.

analysis

The selected title is the minimum mean \ (n-\) , satisfy the following equation \ ((\ PM \) represents preferably a positive number preferably minus \ () \)
\ [\ PM1 \ PM2 \ PM3 \ PM \ cdots \ pm n = \ left | ab
\ right | \ tag {1} \] we let \ (\ left | ab \ right | \) to \ (the X-\) , we first find the smallest \ (k \) satisfy \ (\ {K FRAC * (K + 1)} {2} \ GEQ X \) , i.e. \ ((1) \) where are all plus \ ((\) if the whole is not satisfied plus sign, wherein Some become more minus certainly not satisfied \ () \) . We have a following expression
\ [1 + 2 + \ cdots
+ k = x + y \ tag {2} \] where \ (Y \) is the part in excess.

\ (1 \) if \ (Y \) is even, we know \ (Y <K \) , or do not satisfy the \ (K \) minimum. Then we will \ (\ frac {y} { 2} \) sign becomes negative to satisfy \ ((1) \) formula, the answer is \ (K \) .

\ (2 \) if \ (y \) is odd, then the expression of some positive sign to negative numbers certainly are not satisfied (after changing the value of the change equation is even), we go \ ((2) \) of formula are left plus \ (K +. 1 \) .

  • If \ (k + 1 \) is even, then \ (y + k + 1 \ ) still is odd, supra, is still not satisfied, we need both sides plus \ (k + 2 \) , \ (the y-+ 2 * k + 1 \) is even, we \ (\ frac {y + 1 } {2} \) and \ (K \) sign becomes negative to satisfy \ ((1) \) formula, \ ((y + 1 = 2 * k \) apparently does not satisfy the condition \ () \) , the answer is \ (k + 2 \) .
  • If \ (k + 1 \) is odd, then the \ (y + k + 1 \ ) is even, we \ (\ frac {y + k + 1} {2} (\ frac {y + k + 1} {2} <k + 1) \) sign becomes negative to satisfy \ ((1) \) formula, the answer is \ (k + 1 \)
#pragma GCC optimize(3, "Ofast", "inline")

#include <bits/stdc++.h>

#define start ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define ll long long
#define LL long long
#define pii pair<int,int>
#define int ll
#define ls st<<1
#define rs st<<1|1
using namespace std;
const int maxn = (ll) 1e5 + 5;
const int mod = (ll) 1e9 + 7;
const int inf = 0x3f3f3f3f3f3f3f3f;
int sum[maxn];

signed main() {
    start;
    for (int i = 1; i < maxn; ++i)
        sum[i] = sum[i - 1] + i;
    int T;
    cin >> T;
    while (T--) {
        int a, b;
        cin >> a >> b;
        if (a > b)
            swap(a, b);
        int x = b - a;
        int ans = lower_bound(sum, sum + maxn, x) - sum;
        if ((sum[ans] - x) & 1) {
            if (ans & 1)
                cout << ans + 2 << '\n';
            else
                cout << ans + 1 << '\n';
        } else
            cout << ans << '\n';
    }
    return 0;
}

I now even \ (Div2 \) of \ (B \) can do card one hour, I was really dish

Guess you like

Origin www.cnblogs.com/F-Mu/p/12072341.html