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.
This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.
/*
解题的基本思路是用动态数组B, V分别保存小球的位置和速度方向然后一秒一秒的确定小球位置,
小球先判别是否在线段两头然后移动接下来在判别小球间是否碰撞,如果发生碰撞则双方速度方向改变
*/
# 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 ] < < " " ;
}
}