Problem H
Grey Area
Jinx is navigating through the Grey, trying to make her way back to her hideout. She needs to move in the positive-$x$ direction a distance of $K$ meters through the fissures, traveling at a constant speed $S$ (m/s), but she can pick where she starts her travel through the fissures. Different starting locations will have different wind currents and densities of particles of the Grey, making some starting locations riskier than others.
For each starting location, Jinx has a forecast estimate of the density of the Grey $d$ (mg/$\text{m}^3$) and the velocity of its particles given as a 3D vector $(v_x, v_y, v_z)$ (m/s), representing their velocity along each axis, where both the density of the Grey and the velocity of the particles stays constant for the entirety of her travel. The particles are uniformly dispersed in the air, and once Jinx starts moving, she won’t stop until she reaches her destination.
You notice, in utmost confusion, that Jinx is shaped like a $1\mathrm{m} \times 1\mathrm{m} \times 1\mathrm{m}$ cube. It’s most likely just a side effect of being in the Grey. With no cover to shield here, she can be exposed to the Grey from $5$ of her $6$ sides, since no wind can come from the ground, which is below her in the negative-$y$ direction. Can you determine how much of the Grey she will be exposed to for each possible start time?
You recall from your study of the Grey that for any stationary $1\mathrm{m} \times 1\mathrm{m}$ square in the $x$-$z$ plane, the amount of Grey that it is exposed to from above is $d \cdot t \cdot v$ mg, where $d$ is the density of the Grey (mg/$\text{m}^3$), $t$ is the amount of time the square is exposed to the Grey (s), and $s$ is the speed of the wind in the negative-$y$ direction (m/s). You don’t recall the formulas for the other directions, but you guess that they are probably the same and move on.
Input
The first line contains two space-separated real numbers $K$ $(0 < K \le 1000)$ and $S$ $(0 < S \le 10)$, where $K$ is the distance to Jinx’s hideout in meters (m) and $S$ is Jinx’s speed in m/s. Both are given with at most $6$ digits after the decimal point.
The second line contains one integer $Q$ $(1 \le Q \le 10^5)$, which is the number of starting locations that Jinx is considering. Then follow $Q$ lines, each describing the forecast for one of the potential starting locations. The $i$-th of these lines contains four space-separated real numbers, describing the forecast of the $i$-th starting location:
-
$d_i$ $(0 \le d \le 20)$—the density of the Grey in mg/$\text{m}^3$
-
$v_{i,x}$ $(-30 \le v_{i,x} \le 30)$—the velocity of the particles in the $x$ direction in m/s
-
$v_{i,y}$ $(-30 \le v_{i,y} \le 0)$—the velocity of the particles in the $y$ direction in m/s
-
$v_{i,z}$ $(-30 \le v_{i,z} \le 30)$—the velocity of the particles in the $z$ direction in m/s
Each of the above real numbers are given with at most $6$ digits after the decimal point.
Output
Print $Q$ real numbers, each on their own line, where the $i$-th line contains the total Grey exposure (mg) that Jinx should expect if she decides to start from the $i$-th starting location. The answer will be considered correct if the absolute or relative error is less than $10^{-6}$.
Explanation
You also remember doing a calculation like this before, where $K = 20$ m, $S = 1.5$ m/s, $d = 0.5$ mg/$\text{m}^3$, and $(v_x, v_y, v_z) = (0.7, -3, 1)$ m/s. You had calculated Jinx’s time of travel to be $t = \frac{20 \text{m}}{1.5 \text{m/s}} = 13.333 \text{s}$. Since Jinx would move $1.5$ m/s in the positive $x$ direction and the particles would move $0.7$ m/s in the positive $x$ direction, you found the velocity of the particles with respect to Jinx to be $0.8$ m/s in the negative $x$ direction, and treated Jinx as stationary for the rest of the calculation. With this, you calculated the exposure from each of the faces:
-
Positive $x$ face: $0.5 \cdot 13.333 \cdot 0.8 = 5.333$ mg
-
Negative $y$ face: $0$ mg, since the velocity of the particles is away from this face
-
Positive $y$ face: $0.5 \cdot 13.333 \cdot 3 = 20.000$ mg
-
Positive $z$ face: $0$ mg, since the velocity of the particles is away from this face
-
Negative $z$ face: $0.5 \cdot 13.333 \cdot 1 = 6.666$ mg
Thus, you calculated a total of $32.000$ mg of exposure from the Grey.
Sample Input 1 | Sample Output 1 |
---|---|
20 1.5 6 0 1 -1 1 1 0 0 0 0.5 0.7 -3 1 0.5 0.7 -3 -1 0.84 0.23 -4.2 5.6 8.34 2.3 -3.6 1.5 |
0.000000000000000 20.000000000000000 32.000000000000000 32.000000000000000 123.9840000000000 656.0800000000000 |