You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

40 lines
1.3 KiB

2 years ago
/*
BV
线
*/
#include<bits/stdc++.h>
using namespace std;
int main() {
int n, L, t;//n小球个数L线段长度t时间
cin >> n >> L >> t;
int *B = new int[n];//用来记录n个小球的位置
int *V = new int[n];//用来记录小球的运动方向1代表右-1代表左
for (int i = 0; i < n; i++) {//初始化
cin >> B[i];
V[i] = 1;
}
//一秒一秒的确定小球的位置及运动方向
while (t--) {
for (int i = 0; i < n; i++) {
if (B[i] == 0 || B[i] == L) {
V[i] = -V[i];
}
B[i] = B[i] + V[i];
}
//如果小球碰撞则速度方向改变
for (int i = 0; i < n; i++) {
for (int j = 0; j < n && j != i; j++) {
if (B[i] == B[j]) {
V[i] = -V[i];
V[j] = -V[j];
}
}
}
}
for (int i = 0; i < n; i++) {
cout << B[i] << " ";
}
}