AcWing 3258. 碰撞的小球
原题链接
简单
作者:
把这题Ac了
,
2024-12-05 10:55:33
,
所有人可见
,
阅读 1
#include <iostream>
using namespace std;
const int N = 110,M = 1010,K = 0x3f3f3f3f;
struct node{
int idx,fwd; // fwd = 0向左.fwd = 1 向右
}bound[N];
int d[M];
int step[2] = {-1,1};
int n,l,t;
int main(){
cin >> n >> l >> t;
d[0] = d[l] = 1010;
for(int i = 0;i < n;i++){
int a;
cin >> a;
bound[i].idx = a;bound[i].fwd = 1;
}
for(int i = 1;i <= t;i++){//时间
for(int j = 0;j < n;j++){//球
int flag = 0,t = bound[j].idx;
int cnt = d[bound[j].idx];
if(cnt > 1){
bound[j].fwd ^= 1;
if(cnt == K) d[t] = 0;
else flag = 1;
}
bound[j].idx += step[bound[j].fwd];
if(flag) d[t] = K;
else if(d[t]) d[t]--;
d[bound[j].idx]++;
}
}
for(int i = 0;i < n;i++){
cout << bound[i].idx << ' ';
}
cout << endl;
return 0;
}