弹性碰撞 poj 3684

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 N, H, R, T.
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

题意 : 每隔一秒会释放一个小球,问最终所有小球底端距离地面的位置高度。思路 :  1 . 由于是发生弹性碰撞,即小球发生碰撞后,速度反向,大小不变,因此当两个小球发生  2 .先考虑 小球的半径为 0 的时候,即所有的小球都从同一点释放出去,只是时间不同,计算出所有小球的高度,排序后即为所求  3 . 若有半径,上面的求一定比最下面的球多 2*r*i 的重力势能,因此只需要再加上此高度即可  推荐博客 :http://www.cnblogs.com/smilesundream/p/5134406.html

代码 :
int n, h, r, t;
double arr[105];

double cal(int t){
    if (t < 0) return 1.0*h;
    double t1 = sqrt(2.0*h/10.0);
    int k = t / t1;
    if (k & 1){
        return  1.0*h - 5.0*((k+1)*t1 - t)*((k+1)*t1 - t);
    }
    else {
        return 1.0*h - 5.0*(t - k*t1)*(t - k*t1);
    }
}

int main() {
    //freopen("in.txt", "r", stdin);
    //freopen("out.txt", "w", sttout);
    int T;

    cin >> T;
    while(T--){
        scanf("%d%d%d%d", &n, &h, &r, &t);
        for(int i = 0; i < n; i++){
            arr[i] = cal(t - i);
        }
        sort(arr, arr+n);
        for(int i = 0; i < n; i++){
            printf("%.2lf", arr[i]+2.0*r*i/100.0);
            printf("%c", i+1 == n?‘\n‘:‘ ‘);
        }
    }

    return 0;
}
				
时间: 2024-08-29 02:43:00

弹性碰撞 poj 3684的相关文章

POJ 3684 Priest John&#39;s Busiest Day 2-SAT+输出路径

强连通算法判断是否满足2-sat,然后反向建图,拓扑排序+染色. 一种选择是从 起点开始,另一种是终点-持续时间那个点 开始. 若2个婚礼的某2种时间线段相交,则有矛盾,建边. 容易出错的地方就在于判断线段相交. 若s1<e2&&s2<e1则相交 输出路径的做法可以参考论文2-SAT解法浅析 #include <iostream> #include<cstring> #include<cstdio> #include<string>

poj 3684 Physics Experiment 弹性碰撞

Physics Experiment Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 1489   Accepted: 509   Special Judge Description Simon is doing a physics experiment with N identical balls with the same radius of R centimeters. Before the experiment,

Physics Experiment poj 3684 弹性碰撞

Language: Default Physics Experiment Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 1107   Accepted: 380   Special Judge Description Simon is doing a physics experiment with N identical balls with the same radius of R centimeters. Befor

Physics Experiment(POJ 3684)

原题如下: Physics Experiment Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 3583   Accepted: 1275   Special Judge Description Simon is doing a physics experiment with N identical balls with the same radius of R centimeters. Before the exper

POJ 3684 Physics Experiment

和蚂蚁问题类似. #include<cstdio> #include<cstring> #include<cmath> #include<vector> #include<queue> #include<algorithm> using namespace std; int c,n; double h,r,t,T; double ans[105]; double cal(double time) { if(time<=0) re

常用技巧精选(一)

尺取法 Subsequence(POJ 3061) 原题如下: Subsequence Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 20969 Accepted: 8948 Description A sequence of N positive integers (10 < N < 100 000), each of them less than or equal 10000, and a positive integ

poj 1852&amp;3684 题解

poj 1852 3684 这两题思路相似就放在一起. 1852 题意 一块长为L长度单位的板子(从0开始)上有很多只蚂蚁,给出它们的位置,它们的方向不确定,速度为每秒一长度单位,当两只蚂蚁相遇的时候,它们会反向而行,问所有蚂蚁到达终点(到0或者到L)所需要的最短时间和最长时间. 解析 一开始拿到这题觉得还是有点难度的,但一想通就发现这是个大水题.我们可以假设两只蚂蚁它们相向而行,并且它们中间没有别的蚂蚁,此时它们距离为k,经过时间t后它们相遇,此时它们反向,又经过时间t它们再次之间距离还是k.

POJ 2674-Linear world(弹性碰撞)

Time Limit: 3000MSMemory Limit: 65536K Total Submissions: 3119Accepted: 696 Description The Disc, being flat, has no real horizon. Any adventurous sailors who get funny ideas from staring at eggs and oranges for too long and set out for the antipodes

Greedy:Physics Experiment(弹性碰撞模型)(POJ 3848)

物理实验 题目大意:有一个与地面垂直的管子,管口与地面相距H,管子里面有很多弹性球,从t=0时,第一个球从管口求开始下落,然后每1s就会又有球从球当前位置开始下落,球碰到地面原速返回,球与球之间相碰会发生完全弹性碰撞(各自方向改变,速率变为相碰时另一个球的速率)问最后所有球的位置? 这一题又是一道弹性碰撞模型的题目,和Liner World有点像,但是这一题不要求输出球的名字,而是要你求得各个球的高度 这道题我们只用明白一个道理就很方便了: 首先我们来看一个球的情况: 一个球从H的高度下落,碰到