题解:CF1278B A and B
Bc2_Ch1ckenPr1nce · · 题解
Solution
简单题。
钦定
此时的操作次数显然是满足
但现在
我们便得到
怎么平掉这个差距?如果把前面的操作把
如果
如果
如果
Code
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
const int kMaxN = 1e7 + 10;
ll a, b, x, ans;
int main() {
ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
int t;
for (cin >> t; t; -- t) {
cin >> a >> b;
if (a > b) {
swap(a, b);
}
x = b - a, ans = sqrt(2 * x);
for (; ans * (ans + 1) / 2 > x; -- ans);
x = b - (a + ans * (ans + 1) / 2);
if (!x) {
cout << ans << '\n';
continue;
}
x = b - (a + (ans + 1) * (ans + 2) / 2);
if (x % 2) {
if (ans % 2) {
ans += 2;
} else {
ans += 3;
}
} else {
++ ans;
}
cout << ans << '\n';
}
return 0;
}