poj3684(相遇碰撞模型)

来源:互联网 发布:程序员html5表白网页 编辑:程序博客网 时间:2024/06/05 11:24
/*translation:将N个半径为R的球放入一个圆桶(圆桶口径刚好放入一个球),将圆桶竖直放着,最下端距离地面H高度,让球每隔一秒自由下落,求T时刻各个球距离地面的高度。solution:所有的球都一样可以忽视它们的碰撞,视为互相穿过继续运动。这样就可以分别单独求出每个球T时刻的高度后排序就是答案了。note:注意在开始处理的时候要将所有的球按照高度与地一个小球一样的高度来处理。在输出的时候再加上实际的距离。date:2016.11.10*/#include <iostream>#include <cstdio>#include <cstring>#include <vector>#include <algorithm>#include <cmath>using namespace std;const int maxn = 10000 + 5;int n, h, r, t;vector<double> ans;double compute(double current_h, double current_t){if(current_t < 0)return current_h;double fall_t = sqrt(2.0 * current_h / 10.0);int k = (int)(current_t / fall_t);double time;if(k & 1){time = k*fall_t + fall_t - current_t;}else{time = current_t - k*fall_t;}return current_h - 5.0 * time * time;}int main(){//freopen("in.txt", "r", stdin);    int T;    scanf("%d", &T);    while(T--){scanf("%d%d%d%d", &n, &h, &r, &t);ans.clear();double th;for(int i = 0; i < n; i++){th = compute((double)h,  (double)t - i);ans.push_back(th);}sort(ans.begin(), ans.end());for(int i = 0; i < n; i++){printf("%.2f%c", ans[i] + 2*r*i/100.0, i + 1 == n ? '\n' : ' ');}    }    return 0;}

0 0
原创粉丝点击