头尾链接一下就好,
/* 1 2 3 4 5 6 7:4 5 6 7 1 2 3:2 3 5 6 7 1:5 6 7 1 3:6 7 1 3:1 3 7 */ #include<bits/stdc++.h> using namespace std; int main(){int n,k,q[200],nxt[200],p,pre,tot;scanf("%d%d",&n,&k);for(int i=1;i<=n;i++) q[i]=i,nxt[i]=i+1;nxt[n]=1;tot=n,p=1,pre=n;while(k--){int tmp;scanf("%d",&tmp);tmp%=tot;while(tmp--)pre=p,p=nxt[p];nxt[pre]=nxt[p],tot--,printf("%d ",p),p=nxt[p];} }