poj-3684-Physics-Experiment

Physics Experiment
Time Limit: 1000MS Memory Limit: 65536K
Total Submissions: 1963 Accepted: 667 Special Judge

Description

Simon is doing a physics experiment with N identical balls with the same radius of R centimeters. Before the experiment, all N balls are fastened within a vertical tube one by one and the lowest point of the lowest ball is H meters above the ground. At beginning of the experiment, (at second 0), the first ball is released and falls down due to the gravity. After that, the balls are released one by one in every second until all balls have been released. When a ball hits the ground, it will bounce back with the same speed as it hits the ground. When two balls hit each other, they with exchange their velocities (both speed and direction).

Simon wants to know where are the N balls after T seconds. Can you help him?

In this problem, you can assume that the gravity is constant: g = 10 m/s2.

Input

The first line of the input contains one integer C (C ≤ 20) indicating the number of test cases. Each of the following lines contains four integers NHRT.
1≤ N ≤ 100.
1≤ H ≤ 10000
1≤ R ≤ 100
1≤ T ≤ 10000

Output

For each test case, your program should output N real numbers indicating the height in meters of the lowest point of each ball separated by a single space in a single line. Each number should be rounded to 2 digit after the decimal point.

Sample Input

2
1 10 10 100
2 10 10 100

Sample Output

4.95

4.95 10.20


题意:

n个球被固定在一个圆筒里,保证从t=0开始,每1S下落一个球,球的半径为R,最小面的球底部距地H,g=10m/s*s,球与地面,球与球之间都是弹性碰撞,即与地碰后速度大小不变,方向相反,与球碰后,等效为直接“穿过”,求Ts时间后,各个球的位置。

题目链接:Physics Experiment

解题思路:


第i个球底部距地H+2*i*R(i从0开始),一个球自由下落H所需时间tmp=sqrt(2*H/g),因为球之间的碰撞时弹性的,那么其实等效为两个球没发生碰撞而直接的“穿过”,保持速度继续运动(把此时的状态传给另外一个球)。


因此,T时间内,球就不断地重复着上升运动,来回为一个周期,那么令k=T/tmp,易知k*tmp<=T,


当k为偶数时,实际上最后一段时间,球在下落,全程等效为从初始位置自由下落T-k*tmp时间。当k为奇数时,最后一段时间,球在上升,全程等效为从最高点自由下落(k+1)*tmp-T时间。


最后直接套公式求出高度即可,需要注意当T<0时,剩下的球不会下落。


代码:

#include
   
   
    
      //256K	16MS
#include
    
    
     
     
#include
     
     
      
      
#include
      
      
       
       
#include
       
       
         using namespace std; int T,n,h,r; double ans[110],tmp; double solve(int time) { if(time < 0) return h; int k =(int) time / tmp; //求运动时间为完成一次下落时间的倍数 double s; if(k & 1){ //奇数倍时间,最后是在上升过程,等效为从某一位置自由下落(k+1)*tmp-time时间 s = k * tmp + tmp - time; } else { s = time - k * tmp; //偶数倍时间,最后是在下落过程,等效为自由下落时间为time-k*tmp } return h - 10.0 * s * s / 2.0; } int main() { int c,i; cin>>c; while(c--){ cin>>n>>h>>r>>T; tmp = sqrt(2.0 * h / 10.0); //球自由下落h所需时间 for(i = 0;i < n;i++){ ans[i] = solve(T - i); //每一秒下落一个球,第i个球等于只有T-i的时间运动了 } sort(ans,ans+n); //排序,保证每个球的高度是非递增的 for(i = 0;i < n;i++){ printf("%.2f",ans[i] +(double) i * 2 * r / 100.0); //移动的距离+初始时的高度,记得将厘米化成米 if(i != n - 1) printf(" "); else printf("\n"); } } return 0; } 
       
      
      
     
     
    
    
   
   

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值