题意 N个位置,编号1~n-1.位置i上的元素为i。N个位置中有K个关键位置,初始值为Ai.这些关键元素向右轮换,且加1再模N.求T秒后各位置上的元素。 思路 由题得,对于其中的元素i,他会受到离他最近的关键元素o影响,且离他最近的关键元素还是o。设下一个关键元素与当前元素的差值为d,所以元素i在第一次轮换后,每d秒会向右移动个单位,最后双指针找O. 代码
#include<bits/stdc++.h>
using namespace std;
const int MAXN=200005;
int pos[MAXN],ans[MAXN],n,k,t,dist;
int main(){
cin>>n>>k>>t;
for(int i=0;i<k;i++){
cin>>pos[i];
}
pos[k]=pos[0]+n;
int j=0;
for(int i=0;i<n;i++){
while(pos[j]<=i){
j++;
}
dist=pos[j]-pos[j-1];
int temp=t-i+pos[j]-1;
int step=temp/dist;
int move=step*dist;
int final=(i+move)%n;
ans[final]=i;
}
for(int i=0;i<n;i++){
cout<<ans[i]<<" ";
}
return 0;
}