1 条题解
-
0
题解
先把
1..n全部放入队列。不断处理队首:
- 如果当前报数还没到
m,把队首元素取出后重新放到队尾; - 如果刚好数到
m,输出并删除它,同时把计数重新设为 0。
这是队列“先进先出 + 队首转队尾”的典型模拟。
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(false); cin.tie(nullptr); int n, m; cin >> n >> m; queue<int> q; for (int i=1;i<=n;++i) q.push(i); int cnt=0; bool first=true; while (!q.empty()) { int x=q.front(); q.pop(); ++cnt; if (cnt==m) { if (!first) cout << ' '; first=false; cout << x; cnt=0; } else { q.push(x); } } cout << '\n'; return 0; } - 如果当前报数还没到
- 1
信息
- ID
- 5153
- 时间
- 1000ms
- 内存
- 256MiB
- 难度
- 10
- 标签
- 递交数
- 3
- 已通过
- 2
- 上传者
粤公网安备44195502000252号