[POJ3684]Physics Experiment

 
Time Limit: 1000MS   Memory Limit: 65536K
Total Submissions: 1363   Accepted: 476   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

Source

 

THINKING

  如同POJ1852(ANTS)一样,当R=0时,可认为两个球碰撞后是互相交错而继续运动,当R=0时,处理方法相同,对于从下方开始的第i个球,在R=0的计算上加上d=2*r就好了。

const g:real=10;

var a:array[0..1000] of real;
    n,r,h,t,i,s:longint;

function calc(x:longint):real;
var d,tt:real;k:longint;
begin
    if x<0 then exit(h);
    tt:=sqrt(2*h/g);
    k:=trunc(x/tt);
    if (k mod 2=0) then
        begin
            d:=x-k*tt;
            exit(h-g*d*d/2);
        end
    else
        begin
            d:=k*tt+tt-x;
            exit(h-g*d*d/2);
        end;
end;

procedure sort(l,r:longint);
      var
         i,j:longint;x,y:real;
      begin
         i:=l;
         j:=r;
         x:=a[(l+r) div 2];
         repeat
           while a[i]<x do
            inc(i);
           while x<a[j] do
            dec(j);
           if not(i>j) then
             begin
                y:=a[i];
                a[i]:=a[j];
                a[j]:=y;
                inc(i);
                j:=j-1;
             end;
         until i>j;
         if l<j then
           sort(l,j);
         if i<r then
           sort(i,r);
      end;

procedure main;
var i:longint;
begin
    readln(n,h,r,t);
    for i:=0 to n-1 do
        a[i]:=calc(t-i);
    sort(0,n-1);
    for i:=0 to n-1 do
        begin
            write((a[i]+2*r*i/100):0:2,' ');
        end;
end;

begin
    readln(s);
    for i:=1 to s do main;
end.
View Code
原文地址:https://www.cnblogs.com/yangqingli/p/4889580.html