2018 Beijing University of Information Science and Technology 10th Program Design Competition and ACM Selection J: Physics

#include <bits/stdc++.h>

using namespace std;

intmain()
{
    int T;
    scanf("%d", &T);
    while(T --) {
        int s, v1, v2;
        scanf("%d %d %d", &s, &v1, &v2);
        if(!s) puts("0.0000000000");
        else if(v1 <= v2) puts("Infinity");
        else printf("%.10f\n", s * v1 * 1.0 / (v1 * v1 - v2 * v2));
    }
    return 0;
}

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

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".



#include <bits/stdc++.h>

using namespace std;

intmain()
{
    int T;
    scanf("%d", &T);
    while(T --) {
        int s, v1, v2;
        scanf("%d %d %d", &s, &v1, &v2);
        if(!s) puts("0.0000000000");
        else if(v1 <= v2) puts("Infinity");
        else printf("%.10f\n", s * v1 * 1.0 / (v1 * v1 - v2 * v2));
    }
    return 0;
}

Guess you like

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