题解:B4295 [蓝桥杯青少年组国赛 2022] 报数游戏

· · 题解

Solution

模拟 Y 轮中,每轮报 K 个数的情况,进行标记。

为了方便,将编号设为 0 \sim X + Y - 1,初始编号设为 -1

Code

#include<bits/stdc++.h>
using namespace std;
const int X = 105;
int x, y, k, tp = -1;
bool flg[2 * X];
inline int get(int aa){
    return aa % (x + y);
}
int main(){
    ios::sync_with_stdio(false);
    cin.tie();
    cin >> x >> y >> k;
    for(int p = 1; p <= y; p++){
        for(int q = 1; q <= k; q++){
            tp++;
            while(flg[get(tp)]) tp++;
        }
        flg[get(tp)] = 1;
    }
    for(int i = 0; i < x + y; i++) if(!flg[i]) cout << i + 1 << ' ';
    return 0;
}