ZOJ-3923-In the Rain

ZOJ-3923-In the Rain

Fujiwara no Mokou was formerly an ordinary human, but she became an immortal being after drinking the Hourai Elixir about 1300 years ago. She has some sort of control over fire.

One day, Mokou was on the way home after cutting bamboo. Suddenly it began to rain. As a manipulator of fire, Mokou dislikes rains. So she ran to her home as quickly as possible.
We can regard Mokou as a cylinder. The path can be simplified as a line. Mokou started from (0, 0, 0) and her home is at (x0, 0, 0). It is supposed that the rain is continuous and its density is 1. The rain will be absorbed immediately when it touches the surface of the cylinder or the ground. You need to measure how much weight of rain was absorbed by Mokou during her way to home in the rain.

Input

There are multiple cases. The first line of the input contains an integer T (1 ≤ T ≤ 200) which indicates the number of cases. For each test case:
The first line contains four integers R, H, V, x0, the radius, height and speed of the cylinder and the location of Mokou’s house.
The second line contains three integers dx, dy and dz, the speed of the rain.
All integers in input are no less than -1000 and no larger than 1000. Test data satisfy that R, H, V, x0 > 0, dz < 0.

Output

For each case, output the total weight of rain which was absorbed by Mokou. Absolute or relative error no more than 1E-6 will be accepted.

Sample Input
2
1 1 1 1
0 0 -1
2 3 3 3
2 3 -3

Sample Output
5.1415926536
75.6464437651

题目链接:ZOJ-3923

题目思路:我们假设人不动,雨下落可看成两部分,一部分是头顶:面积为 PI * r * r;另一部分为侧面,可看成长方形,面积为:2 * h * r (圆柱直径所在长方形)

PS:注意变量不要写混。

因为给的样例,h,v,x0等都是一样的导致,找了很久bug,最后发现x1-=v,写成了x1-=x0

以下是代码:

#include<iostream>
#include<cstdio>
#include<cmath>
using namespace std;
#define P acos(-1)
int main(){
    int t;
    //cin >> t;
    scanf("%d", &t);
    while( t-- ){
           double r, h, v, x0, x1, y1, z1;
           cin >> r >> h >> v >> x0 >> x1 >> y1 >> z1;
           x1-=v;   //雨在x上面的相对速度(即减去人移动的速度)
           double xy = sqrt(x1*x1+y1*y1);   //在xy平面上雨下落的速度
           double t = x0/v;  // 回家所需时间
           double ans = P*r*r*-z1*t;   //头顶 ,在z移动
           ans += 2*h*r*xy*t;  //侧面,在xy平面上移动
           printf("%.16lf\n", ans);
    }
    return 0;
}

你可能感兴趣的:(ZOJ,3923)