题意: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;
}