(HDU 5761) 2018 Beijing University of Information Science and Technology 10th Program Design Competition and ACM Selection Competition-Crossing the River (Physics-Mathematics-Decomposition)


Topic description


Now Mengxin wants to cross a river by boat, the width of the river is s meters.
It is now known that the speed of the boat relative to the water is v 1 and the speed of the current is v 2 .
Since Mengxin wants to reach the opposite bank of the starting point, he will always adjust the direction of the boat to face the opposite bank.

Your task is to calculate how long Mengxin will take to cross the river; if he can't reach the opposite bank of the starting point, output "Infinity".

Enter description:

Enter an integer n in the first line, indicating the number of test cases;
Next n lines, enter three integers s, v 1 , v 2 in each line .
Among them, 1≤n≤1000, 0≤s≤100, 0≤v 1 , v 2 ≤100.

Output description:

Output a real number, your task is to calculate how long Mengxin will take to cross the river (10 decimal places); if he cannot reach the opposite bank of the starting point, output "Infinity".
Example 1

enter

3
2 2 2
2 4 3
5 6 5

output

Infinity
1.1428571429
2.7272727273

.

Discuss v1 and v2 by case, first decompose v1, we can see that v1 sinθ and v2 cancel each other out, then since the boat is facing the direction of the end point and the direction of water flow must remain unchanged, the formula can be obtained 
1. ʃ(v1sinθ)dt = ʃ(v2)dt . (The distance between the two sides is equal, it just cancels out, and the horizontal direction does not move)

If v1 < v2 it is absolutely impossible to achieve 

2.  ʃ(v1 - v2sinθ)dt = s  .

The two equations are combined, and the same ʃ(sinθ)dt cancels out, and the equation related to t can be obtained.

t = s * v1 /(v1*v1 - v2*v2) . 

Code below:
#include <iostream>
#include<iomanip>
#include<cstdio>
using namespace std;
intmain()
{
    int n;
    scanf("%d",&n);
    while(n--)
    {
        double a,v1,v2;
        scanf("%lf %lf %lf",&a,&v1,&v2);
        if(a==0)
            printf("0.0000000000\n");
        else if(v1<=v2||v1<=0)
            printf("Infinity\n");
        else
        {
            printf("%.10f\n",a*v1/(v1*v1-v2*v2));
        }
    }
    return 0;
}



Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=326747396&siteId=291194637