codevs1282 约瑟夫问题
来源:互联网 发布:ubuntu输入法没了 编辑:程序博客网 时间:2024/06/05 07:03
#include<iostream> #include<cassert> #include<cstdio> #include<cstring> #include<algorithm> #include<cmath> #include<string> #include<iterator> #include<cstdlib> #include<vector> #include<stack> #include<queue> #include<map> #include<set> using namespace std; #define debug(x) cout<<"debug "<<x<<endl; #define rep(i,f,t) for(int i = (f),_end_=(t); i <= _end_; ++i) #define rep2(i,f,t) for(int i = (f),_end_=(t); i < _end_; ++i) #define dep(i,f,t) for(int i = (f),_end_=(t); i >= _end_; --i) #define dep2(i,f,t) for(int i = (f),_end_=(t); i > _end_; --i) #define clr(c, x) memset(c, x, sizeof(c) ) typedef long long int64; const int INF = 0x5f5f5f5f; const double eps = 1e-8; const int maxn = 30005; #define MID int mid = (L + R)>>1; #define CHILDEN int lc = node<<1, rc = node<<1|1; struct sgt { int T[maxn<<2]; void build(int node,int L,int R){ if(L == R)T[node] = 1; else{ MID;CHILDEN; build(lc,L,mid); build(rc,mid+1,R); T[node] = T[lc]+T[rc]; } } void update(int pos,int node,int L,int R){ if(L == R){ assert(pos == L); T[node] = 0; }else{ MID;CHILDEN; if(pos <= mid) update(pos,lc,L,mid); else update(pos,rc,mid+1,R); T[node] = T[lc] + T[rc]; } } int query(int pos,int node,int L,int R){ assert(T[node] >= pos); if(L == R)return R; MID;CHILDEN; if(pos > T[lc])return query(pos-T[lc],rc,mid+1,R); else return query(pos,lc,L,mid); } }tree; int main() { int n,m; scanf("%d%d",&n,&m); tree.build(1,1,n); int i = 0; for(int len = n; len > 1; --len){ int j = (i+m-1)%(len); int ans = tree.query(j+1,1,1,n); tree.update(ans,1,1,n); printf("%d ",ans); i = j%(len-1); } printf("%d\n",tree.query(1,1,1,n)); return 0; }
0 0
- codevs1282 约瑟夫问题
- codevs1282 约瑟夫问题
- codevs1282 约瑟夫问题 线段树
- codevs1282 约瑟夫问题(线段树)
- 【codevs1282】约瑟夫问题,卡数据ing?
- 【Codevs1282】 约瑟夫问题 树状数组 (11/1000)
- 约瑟夫问题、约瑟夫环
- 约瑟夫问题
- 约瑟夫问题
- 约瑟夫问题
- 约瑟夫问题
- 约瑟夫问题
- 约瑟夫问题
- 约瑟夫问题
- 约瑟夫问题
- 约瑟夫问题
- 约瑟夫问题
- 约瑟夫问题
- codevs2806红与黑
- Android自定义view
- Junit使用
- NSURLSession
- GSP Algorithm: Sequence Mining.
- codevs1282 约瑟夫问题
- MATLAB入门教程(转载)
- hdu1203 I need a offer 01背包
- 2015年度规划
- Java IO流
- hdu_1072_nightmare_BFS_用时间来限定
- 在Winform Design设计器内允许修改UserControl内的控件
- 杂谈记
- linux c++ socket入门之tcp server端