2018_2_4_Roman Roulette_模拟STL_vector_约瑟夫环_升级版
2018-02-04 16:57
393 查看
https://vjudge.net/problem/UVA-130
https://www.cnblogs.com/devymex/archive/2010/09/04/1813034.html
https://www.cnblogs.com/devymex/archive/2010/09/04/1813034.html
#include<cstdio> #include<iostream> #include<vector> using namespace std; int main(){ int n,k; while(scanf("%d%d",&n,&k),n&&k){ vector<int> v; for(int i=0;i<n;v.push_back(++i)); for(int m=(k-1)%v.size(),t;v.size()!=1;){ t=(m+k-1)%(v.size()-1); if(t>=m)t=(t+1)%v.size(); v[m]=v[t]; v.erase(v.begin()+t); m=(m+k-(t<m))%v.size(); } cout<<(n-v.front()+1)%n+1<<endl; } }
相关文章推荐
- 用Vector模拟STL下的stack容器
- Counting-out Rhyme<vector实现约瑟夫环模拟>
- 2018_1_30_Run Length Encoding_string_STL_模拟
- 模拟实现STL中的vector
- STL库中的vector的使用和模拟实现
- hdu 4841 圆桌问题(用vector模拟约瑟夫环)
- Doing Homework Again贪心------[NWPU][2018寒假作业][通用版]二、stl ,模拟,贪心等 [Cloned]P题
- hdu 圆桌问题(STL(vector)的模拟)
- STL中vector的使用以及模拟实现
- STL-模拟实现vector(含类型萃取)
- STL模拟实现vector
- STL应用:PJ的情书:纯模拟,桶排去重加上pair,用vector进行cmp重载
- (线性数据结构5.4.1)UVA 130 Roman Roulette(标准约瑟夫环问题+替换者)
- 2015-2016 ACM-ICPC, NEERC, Southern Subregional Contest A Email Aliases(模拟STL vector+map)
- 【STL】 vector 模拟实现
- UVa 101 The Blocks Problem 【STL】【vector】【模拟】
- 模拟实现STL-Vector
- 【STL】之Vector的模拟实现
- stl的map1------[NWPU][2018寒假作业][通用版]二、stl ,模拟,贪心等 [Cloned]A题
- STL库中vector的模拟