这一题没有思路,因为严格考虑小球碰撞的话,会觉得很乱,无从下手= =
参考大佬的代码:
https://blog.csdn.net/SongBai1997/article/details/81175312
这题对于map的使用很巧妙,应该记下来,后面再遇到这种相对位移的题,都可以考虑下map
AC代码:
#include <stdio.h>
#include <map>
#include <algorithm>
#include <string.h>
using namespace std;
int main(){
int n,L,t;
int tmp[100],ans[100],a[100];
map<int,int>dis;
scanf("%d%d%d",&n,&L,&t);
for(int i = 0;i <n;i++){
scanf("%d",&a[i]);
tmp[i] = a[i];
int temp = a[i]+t;
temp = temp%(2*L);
if(temp>L){
ans[i] = L- temp%L;
}
else{
ans[i] = temp;
}
}
sort(tmp,tmp+n);
sort(ans,ans+n);
for(int i = 0;i <n;i++){
dis[tmp[i]] = i;
}
for(int i = 0;i <n;i++){
printf("%d ",ans[dis[a[i]]]);
}
}
/*
10 22 30
14 12 16 6 10 2 8 20 18 4
*/