1 solutions
-
0
#include <bits/stdc++.h> using namespace std; vector<int> v; int main(){ int n,m,index = 0; cin>>n>>m; for(int i = 1 ; i <= n ; i++){ v.push_back(i); } while(v.size() != 1){ index = (index + m - 1) % v.size();//每次计算出删除的下标,基于每次删除后开始的index v.erase(v.begin() + index);//因为删除后数组自动补齐,因此index即为删除的下标,也为下一个开始的下标 } cout<<v.front()<<endl; return 0; }
Information
- ID
- 841
- Time
- 1000ms
- Memory
- 128MiB
- Difficulty
- 6
- Tags
- # Submissions
- 54
- Accepted
- 16
- Uploaded By