题解:P15328 [GCPC 2025] Around the Table

· · 题解

题意

左右各有 \ell,r 个小朋友,每打完一局,开头的小朋友就跑到对方的最后面,求有多少种配对。

思路

我们发现,只要配对方案和第一种一样就停止,一般在第 2\times(\ell+r) 次后就和第一次一样,我们就要统计这里有多少种不同的配对。

考虑分类讨论:

code

#include <bits/stdc++.h>
//#include <windows.h>
#define For(i,a,b) for(ll i=a;i<=b;i++)
#define Down(i,a,b) for(ll i=a;i>=b;i--)
using namespace std;
typedef long long ll;
typedef string str;
ll l,r;
int main() {
    cin>>l>>r;
    if(l==r) cout<<3*l;
    else if(l==r+1) cout<<l+r;
    else if(l==r+2) cout<<3*r+3;
    else cout<<2*(l+r);
    return 0;
}