zoukankan      html  css  js  c++  java
  • Han Move(细节题)

    Problem 1609 - Han Move
    Time Limit: 1000MS   Memory Limit: 65536KB    Total Submit: 620  Accepted: 162  Special Judge: No
    Description
    Cyy and Fzz are Han Move lovers. One day, they gather together to run. They choose a circular track whose length is L m. Cyy’s speed is A m/s and Fzz’s speed is B m/s. They may choose the direction separately, i.e. they may start with the same direction or different direction. As they’re crazy, they’ll run infinitely. Gatevin, their friend, wonders the possibility of their distance is less than D m. The distance is defined as the distance on the track. The possibility is defined as the ratio between the sum of time satisfying the condition and the total time.
    Input
    The input file consists of multiple test cases ( around 1000000 ). Each test case consists of 5 integers L, A, B, D, Dir in a line. The meanings of L, A, B, D are as described above. Dir means whether they are in the same direction. Dir = 1 means they are in the same direction, while Dir = 0 means they are in the opposite direction. ( 1 <= L, A, B, D <= 32768, 0 <= Dir <= 1 )
    Output
    For each test case, output the possibility rounded to 6 demical places in a line.
    Sample Input
    1200 200 400 300 0 1200 200 400 300 1
    Sample Output
    0.500000 0.500000
    题解:两个人正反跑无限跑,问两个人距离为D以内的概率;注意细节;
    代码:
    #include<iostream>
    #include<cstdio>
    #include<cstring>
    #include<cmath>
    #include<algorithm>
    using namespace std;
    const int INF = 0x3f3f3f3f;
    typedef long long LL;
    int main(){
        double L,A,B,D,ans;
        int Dir;
        while(~scanf("%lf%lf%lf%lf%d",&L,&A,&B,&D,&Dir)){
            if(D >= L){
                puts("1.000000");
                continue;
            }
            if(D == 0 && A == B && Dir){
                puts("1.000000");
                continue;
            }
            if(D == 0){
                puts("0.000000");
                continue;
            }
            if(Dir){
                if(A == B){
                    puts("0.000000");
                    continue;
                }
                double p1 = L / fabs(A - B);
                double p2 = 2 * D / fabs(A - B);
                ans = p2 / p1;
            }
            else{
                double p1 = L / fabs(A + B);
                double p2 = 2 * D / fabs(A + B);
                ans = p2 / p1;
            }
            if(ans >= 1){
                ans = 1;
            }
            printf("%.6lf
    ",ans);
        }
        return 0;
    }
  • 相关阅读:
    poj2392 Space Elevator(多重背包问题)
    poj1703 Find them, Catch them(并查集的应用)
    HDU 1867 A + B for you again(KMP算法的应用)
    HDU 1358 Period(kmp简单解决)
    nyoj 460 项链 (区间dp)
    Python内置函数(9)——callable--转载
    Python的hasattr() getattr() setattr() 函数使用方法详解--转载
    python assert 断言详细用法格式
    sam文件格式
    Linux中重定向--转载
  • 原文地址:https://www.cnblogs.com/handsomecui/p/5372949.html
Copyright © 2011-2022 走看看