2018 Beijing University of Information Science and Technology 10th Program Design Competition and ACM Selection Competition J Crossing the River

Link: https://www.nowcoder.com/acm/contest/118/J
Source: Niuke.com

cross the river
Time limit: C/C++ 1 second, other languages ​​2 seconds
Space limit: C/C++ 32768K, other languages ​​65536K
64bit IO Format: %lld

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; in 
the next n lines, enter three integers s, v in each line
1
、v
2
. 
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 
This question is guessed
#include<iostream>
#include<cstring>
#include<string>
#include<cmath>
#include <queue>
#include<stack>
#include<cstdio>
#include<vector>
#include<deque>
#include<algorithm>
#include<iomanip>
#define inf 0x3f3f3f3f
#define ll long long
using namespace std;
int main()
{
    int n;
    cin>>n;
    while(n--)
    {
        int s,v1,v2;
        cin >>s>>v1>> v2;
         if (s== 0 ) cout<< " 0.0000000000 " <<endl; // This step is too important, only 2% without it 
        else  if (v1<=v2) cout<< " Infinity " << endl;
         else
        {
            printf("%.10lf\n",1.0*s*v1/((v1*1.0+v2)*(v1-v2)));
        }
    }
    return 0;
}
 
      

 

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325343728&siteId=291194637