3 条题解
-
0
数组方式:
#include <bits/stdc++.h> #define N 1001 using namespace std; int q[N]; int main() { int n,m; cin>>n>>m; for(int i=1;i<=n;i++) q[i]=i; int head=1,tail=n+1; int cnt=0; while(head<tail) { cnt++; int p=q[head]; if(cnt==m) { cnt=0; cout<<p<<" "; } else { q[tail]=p; tail++; } head++; } cout<<endl; return 0; } -
0
方法3:
#include <bits/stdc++.h> using namespace std; int main() { int n, m; cin >> n >> m; queue<int> a; for (int i = 0; i < n; i++) { a.push(i); } int c = 1; while (!a.empty()) { int x = a.front(); a.pop(); if (c == m) { cout << x + 1 << " "; c = 1; } else { c++; a.push(x); } } return 0; }
- 1
信息
- ID
- 812
- 时间
- 1000ms
- 内存
- 256MiB
- 难度
- 7
- 标签
- 递交数
- 14
- 已通过
- 11
- 上传者