CF1835A 题解
洛谷传送门 & CF 传送门
思路
题目中有句很重要的话:
Each input file has at most
5 test cases which do not satisfyA,B,C\leq3 .
这意味着
我们可以枚举每个
代码
# include <bits/stdc++.h>
typedef long long ll;
using namespace std;
int t, a, b, c, lg[10], x;
ll k;
int main () {
ios::sync_with_stdio (0);
cin.tie (0);
cout.tie (0);
cin >> t;
while (t --) {
cin >> a >> b >> c >> k;
x = max (a, b);
if (c != x && c != x + 1) { //不可能有解啊
cout << "-1\n";
continue ;
}
for (int i = lg[a - 1]; i < lg[a]; ++ i) {
x = max (0, min (lg[b], lg[c] - i) - max (lg[b - 1], lg[c - 1] - i));
if (k > x) {
k -= x;
continue ;
}
k += max (lg[b - 1], lg[c - 1] - i) - 1;
cout << i << " + " << k << " = " << i + k << '\n';
goto there; //使程序跳转到 there 的地方继续执行
}
cout << "-1\n";
there:
;
}
return 0;
}