题解:P15328 [GCPC 2025] Around the Table
xiaozhengguoaaa · · 题解
签到题。
主要思路
左侧
通过分析状态转移的周期性:
-
状态由 (左边队首, 右边队首) 组成。
-
不考虑发球权:
-
考虑发球权后:
完整周期是
2 与l 和r 的最小公倍数的乘积。 -
不同
l 和r 的关系会导致某些配对重复出现的次数不同。
然后按照规律来做就可以了。
AC code:
#include <bits/stdc++.h>
#define int long long
#define fst ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
using namespace std;
typedef long long ll;
typedef pair<int, int> PII;
const int N = 4e6 + 7;
const int MOD = 998244353;
const int INF = 0X3F3F3F3F;
const int dx[] = {-1, 1, 0, 0, -1, -1, +1, +1};
const int dy[] = {0, 0, -1, 1, -1, +1, -1, +1};
int a[N], c[N], b[N];
bool v[N];
int n, k, m;
int t;
inline int read()
{
int s = 0, w = 1;
char ch = getchar();
while (ch < '0' || ch > '9')
{
if (ch == '-')
w = -1;
ch = getchar();
}
while (ch >= '0' && ch <= '9')
{
s = s * 10 + ch - '0';
ch = getchar();
}
return s * w;
}
inline void write(int x)
{
if (x < 0) putchar('-'), x = -x;
if (x > 9) write(x / 10);
putchar(x % 10 + '0');
return;
}
signed main()
{
fst;
int l, r;
cin >> l >> r;
if (l == r)
{
// 情况A: 左右人数相等
cout << 3 * l;
}
else if (l == r + 1)
{
// 情况B: 左侧比右侧多1人
cout << l + r;
}
else if (l == r + 2)
{
// 情况C: 左侧比右侧多2人
cout << 3 * (r + 1);
}
else
{
// 情况D: 其他所有情况
cout << 2 * (l + r);
}
return 0;
}