1 条题解
-
0
按剩余人数对报数步长取模,避免大m导致超时和加法溢出。
#include <bits/stdc++.h> using namespace std; int main(){ios::sync_with_stdio(false);cin.tie(nullptr); int n;long long m;cin>>n>>m;vector<int>a(n);iota(a.begin(),a.end(),1);size_t index=0;bool first=true;while(!a.empty()){index=(index+(m-1)%a.size())%a.size();cout<<(first?"":" ")<<a[index];first=false;a.erase(a.begin()+index);}cout<<"\n"; return 0; }
- 1
信息
- ID
- 4009
- 时间
- 1000ms
- 内存
- 128MiB
- 难度
- 5
- 标签
- 递交数
- 0
- 已通过
- 0
- 上传者