codeforces 792 B. Counting-out Rhyme (模拟链表||约瑟夫环)
来源:互联网 发布:2016网络自制剧排行榜 编辑:程序博客网 时间:2024/06/05 01:09
题意:n个人占成一圈,每点ai个人淘汰一个,输出淘汰顺序
解题思路:直接用数组模拟链表遍历即可
#include<bits/stdc++.h>using namespace std;const int N = 111;int pre[N],nnext[N];int main(){ int n,m,num,first; int last,Next; int i,j; cin>>n>>m; pre[1]=n,nnext[1]=2; for(i=2;i<=n;i++) { pre[i]=i-1; nnext[i]=i+1; } nnext[n]=1; first=1; while(m--) { cin>>num; num%=n; while(num--) { first=nnext[first]; } last = pre[first]; Next = nnext[first]; nnext[last] = Next; pre[Next] = last; cout<<first<<" "; first = nnext[first]; n--; } cout<<endl; return 0;}
0 0
- codeforces 792 B. Counting-out Rhyme (模拟链表||约瑟夫环)
- CodeForces 792B Counting-out Rhyme
- codeforces B. Counting-out Rhyme
- CF 792B Counting-out Rhyme 模拟约舍夫环
- Counting-out Rhyme codeforces
- Codeforces Counting-out Rhyme
- B. Counting-out Rhyme
- Codeforce 792B Counting-out Rhyme
- 【扩展欧几里得】总结//poi 2002 Counting-Out Rhyme
- 约瑟夫环问题(双向循环链表模拟)
- CodeForces 754B(模拟)
- codeforces 839B(模拟)
- 约瑟夫环(纯模拟)
- zoj1088(模拟/约瑟夫环)
- Codeforces 429B B. Working out (DP)
- Codeforces 429B Working out
- CodeForces 429B Working out
- CodeForces 429B Working out
- 跟着Andrew Ng挑战Machine Learning(第二周):多元线性回归+特征缩放
- hdu 2159 FATE
- 同步,异步,阻塞,非阻塞 和 几种网络模型
- 洛谷 2023_[AHOI2009]维护序列_线段树
- 记一些问题
- codeforces 792 B. Counting-out Rhyme (模拟链表||约瑟夫环)
- eclipse 面包屑开关
- ios xcode 字体大全
- 学习笔记:SAE TensorFlow代码
- Erlang/OTP: 基于 Behaviour 的回调函数【转】
- A1063.Set Similarity
- 页面的分页(对之前上传的的代码的一种补充)
- Linux(2)简单的导航指令(下)绝对路径和相对路径
- 【JavaScript】2.JavaScript&html