zoukankan      html  css  js  c++  java
  • UVA

                            Joining with Friend

    You are going from Dhaka to Chittagong by train and you came to know one of your old friends is going
    from city Chittagong to Sylhet. You also know that both the trains will have a stoppage at junction
    Akhaura at almost same time. You wanted to see your friend there. But the system of the country is
    not that good. The times of reaching to Akhaura for both trains are not fixed. In fact your train can
    reach in any time within the interval [t1, t2] with equal probability. The other one will reach in any
    time within the interval [s1, s2] with equal probability. Each of the trains will stop for w minutes after
    reaching the junction. You can only see your friend, if in some time both of the trains is present in the
    station. Find the probability that you can see your friend.
    Input
    The first line of input will denote the number of cases T (T < 500). Each of the following T line will
    contain 5 integers t1, t2, s1, s2, w (360 ≤ t1 < t2 < 1080, 360 ≤ s1 < s2 < 1080 and 1 ≤ w ≤ 90). All
    inputs t1, t2, s1, s2 and w are given in minutes and t1, t2, s1, s2 are minutes since midnight 00:00.
    Output
    For each test case print one line of output in the format ‘Case #k: p’ Here k is the case number and
    p is the probability of seeing your friend. Up to 1e − 6 error in your output will be acceptable.
    Sample Input
    2
    1000 1040 1000 1040 20
    720 750 730 760 16
    Sample Output
    Case #1: 0.75000000
    Case #2: 0.67111111

    题意:

    : 

    讨论就是了

    #include <iostream>
    #include <cstdio>
    #include <cmath>
    #include <cstring>
    #include <algorithm>
    using namespace std ;
    typedef long long ll;
    
    const int N=10000;
    
    double sum,s1,s2,t1,t2,w;
    double cal(double k) {
        double ans = 0;
        if(s2 > t2 + k && s1 > t1 + k)  {
            double tmp = t2 + k - s1;
            tmp = tmp < 0 ? 0 : tmp;
            ans = sum - (tmp) * (tmp) / 2.0;
        }
        else if(s2 > t2 + k) {
            double l = s2 - (t1 + k);
            double r = s2 - (t2 + k) + l;
            ans =  r * (t2 - t1) / 2.0;
        }
        else if(s1 > t1 + k) {
            double l = s2 - k -t1;
            double r = s1 - k -t1 + l;
            ans = r * (s2 - s1) / 2.0;
        }
        else {
            double tmp = s2 - k - t1;
            tmp = tmp < 0 ? 0 : tmp;
            ans = tmp * tmp / 2.0;
        }
        if(k < 0)  ans = sum - ans;
        return ans;
    }
    int main() {
        int T, cas = 1;
        scanf("%d",&T);
        while(T--) {
          scanf("%lf%lf%lf%lf%lf",&t1,&t2,&s1,&s2,&w);
          sum = 1.0 * (s2 - s1) * (t2 - t1) ;
          double ans = cal(w) + cal(-w);
          printf("Case #%d: %.6f
    ", cas++, 1 - ans * 1.0 / sum);
        }
        return 0;
    }
    代码
  • 相关阅读:
    团队博客-会议之初
    5.2 个人作业2
    5.1 如何利用Intellij Idea搭建python编译运行环境
    4.27 python神器——Anaconda的安装与优化配置
    4.26 AlertDialog(对话框)详解
    4.25 xmapp启动mysql出现Error: MySQL shutdown unexpectedly.
    4.24 Android Studio下应用签名的方法以及获取 MD5、SHA1(签名)、SHA256 值
    4.23 2020.2新版本idea创建javaEE web文件
    4.22 Android studio 通过获取验证码用户登陆成功
    4.21 Android 记住密码和自动登录界面的实现(SharedPreferences 的用法)
  • 原文地址:https://www.cnblogs.com/zxhl/p/5119998.html
Copyright © 2011-2022 走看看