也是超简单
2026-06-27 16:19:14
发布于:四川
10阅读
0回复
0点赞
#include<bits/stdc++.h>
using namespace std;
#define int long long
int T , C;
int f(int t , int x) {
//我们以f(t,x) = t/2作为开端
if (t + t / 2 + 1 <= T) {
return f(t + t / 2 + 1, x);
}
else {
return t / 2 - (T - t);
}
}
//第t轮结束,下标为x
int g(int t , int x) {
if (t == 0 && x == 0) {
return 0;
}
if (x > t / 2) {
return x;
}
else if (x == t/2){
return g(t - 1,0);
}
else {
//t--,x++
//t + x 是一个定值
//已知递归到 x == t / 2
int tot = (t + x);
int nxt_x = tot / 3;
int nxt_t = tot - nxt_x;
if (nxt_x == nxt_t / 2) {
return g(nxt_t, nxt_x);
}
else {
return g(nxt_t - 1 , nxt_x + 1);
}
}
}
signed main() {
int q;
cin >> q;
for (int i = 1 ; i <= q ; i ++) {
int op;
cin >> op;
if (op == 1) {
cin >> T >> C;
if (C > T / 2) {
cout << C << endl;
}
else if (3 * C > T) {
//从 t / 2 == c 开始,每一轮都会减去,一共减去c轮
cout << C - (T - 2 * C + 1) << endl;
}
else {
cout << f(3 * C ,C) << endl;
}
}
else {
cin >> T >> C;
cout << g(T , C) << endl;
}
}
}//就是按照题目要求一步一步算就能出结果
全部评论 2
我妈偏让我打注释(我不想打😭)2026-06-27 来自 四川
0(借助了我爸的一点帮助而已)2026-06-27 来自 四川
0








有帮助,赞一个