2018年北京信息科技大学第十届程序设计竞赛暨ACM选拔赛 J过河

链接:https://www.nowcoder.com/acm/contest/118/J
来源:牛客网

过河
时间限制:C/C++ 1秒,其他语言2秒
空间限制:C/C++ 32768K,其他语言65536K
64bit IO Format: %lld

题目描述


现在萌新要乘船度过一条河,这条河宽为s米。
现已知船相对于水的速度为v 1,水流的速度为v 2
由于萌新想到达起点的正对岸,所以他会一直调整船行驶的方向朝向正对岸。

你的任务是计算萌新将用多少时间度过这条河;若他不能到达起点的正对岸,输出“Infinity”。

输入描述:

第一行输入一个整数n,表示测试用例数;
接下来n行,每行输入三个整数s、v
1
、v
2

其中,1≤n≤1000,0≤s≤100, 0≤v
1
,v
2
≤100。

输出描述:

输出一个实数,你的任务是计算萌新将用多少时间度过这条河(保留10位小数);若他不能到达起点的正对岸,输出“Infinity”。
示例1

输入

3
2 2 2
2 4 3
5 6 5

输出

Infinity
1.1428571429
2.7272727273
这题是猜出来的
#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;//这步太重要,没有它只过了2%
        else if(v1<=v2)cout<<"Infinity"<<endl;
        else
        {
            printf("%.10lf\n",1.0*s*v1/((v1*1.0+v2)*(v1-v2)));
        }
    }
    return 0;
}