POJ 3684 Physics Experiment

poj 3684

Physics Experiment
Time Limit: 1000MS   Memory Limit: 65536K
Total Submissions: 1949   Accepted: 661   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).

POJ 3684 Physics Experiment_第1张图片

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

POJ Founder Monthly Contest – 2008.08.31, Simon

解题思路:

”they with exchange their velocities (both speed and direction)“等质量小球在完全弹性碰撞时互相交换速度(动量守恒)。
由于球与球除了顺序没有什么区别,碰撞时可以看作并没有弹回,而是交换位置继续前进,而球的次序的固定不变的,在碰撞过程中,球的大小没有影响,所以可以把球看成一个点来处理,最后再加上下方球所占的高度。球随时间的高度变化应该都会求,这题要注意的是每秒掉下一个球,在T时间内可能还没下落,没考虑到这个WA到死。。。总的来说这题还是很巧妙地,本渣看到就相放弃来着。。。

代码:

#include<iostream>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<cmath>
#include<algorithm>
#include<map>
#include<string>
#include<queue>
#include<vector>
#include<list>
//#pragma comment(linker,"/STACK:1024000000,1024000000")
using namespace std;
#define INF 0x3f3f3f3f
int n;
int a[4005][5];
int sum[16000005],cnt=0;
int main()
{
    while(~scanf("%d",&n))
    {
        cnt=0;
        for(int i=1;i<=n;i++)
            for(int j=1;j<=4;j++)
            scanf("%d",&a[i][j]);
        long long ans=0;
        for(int i=1;i<=n;i++)
            for(int j=1;j<=n;j++)
                sum[cnt++]=a[i][1]+a[j][2];
        sort(sum,sum+cnt);
        for(int i=1;i<=n;i++)
            for(int j=1;j<=n;j++)
            {
                int l=lower_bound(sum,sum+cnt,-a[i][3]-a[j][4])-sum;
                int r=upper_bound(sum,sum+cnt,-a[i][3]-a[j][4])-sum;
                ans+=r-l;
            }
        printf("%I64d\n",ans);
    }
    return 0;
}


你可能感兴趣的:(POJ 3684 Physics Experiment)