zoukankan      html  css  js  c++  java
  • UVA11722 Jonining with Friend

    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

    比较显然的线性规划,几何概型,之前一道类似的题出到了我们数学卷子上,被我秒了。。。

    主要是求面积,分好情况

     1 #include <iostream>
     2 #include <cstdio>
     3 #include <cstring>
     4 #include <cstdlib>
     5 #include <algorithm>
     6 #include <queue>
     7 #include <vector>
     8 #include <cmath> 
     9 #define min(a, b) ((a) < (b) ? (a) : (b))
    10 #define max(a, b) ((a) > (b) ? (a) : (b))
    11 #define abs(a) ((a) < 0 ? (-1 * (a)) : (a))
    12 inline void swap(int &a, int &b)
    13 {
    14     long long tmp = a;a = b;b = tmp;
    15 }
    16 inline void read(int &x)
    17 {
    18     x = 0;char ch = getchar(), c = ch;
    19     while(ch < '0' || ch > '9') c = ch, ch = getchar();
    20     while(ch <= '9' && ch >= '0') x = x * 10 + ch - '0', ch = getchar();
    21     if(c == '-') x = -x;
    22 }
    23 
    24 const int INF = 0x3f3f3f3f;
    25 
    26 int t1,t2,s1,s2,t,ca,w;
    27 
    28 double calc(int w)
    29 {
    30     if(t1 + w >= s2) return (s2 - s1) * (t2 - t1);
    31     if(t2 + w <= s1) return 0;
    32     if(t1 + w >= s1)//left
    33     {
    34         if(s2 - w >= t2) return (double)(t1 + w - s1 + t2 + w - s1) * (t2 - t1) * 0.5; //right 
    35         else return (s2 - s1) * (t2 - t1) - (double)(s2 - t1 - w) * (s2 - w - t1) * 0.5; //up 
    36     }
    37     else
    38     {
    39         if(s2 - w >= t2) return (double)(t2 + w - s1) * (t2 - s1 + w) * 0.5; //right
    40         else return (double)(t2 - s2 + w + t2 - s1 + w) * (s2 - s1) * 0.5;//up 
    41     }
    42     return 0;
    43 }
    44 
    45 int main()
    46 {
    47     read(t);
    48     for(;t;--t)
    49     { 
    50         ++ ca;
    51         read(t1), read(t2), read(s1), read(s2), read(w);
    52         printf("Case #%d: %.8lf
    ", ca, (calc(w) - calc(-w)) / ((s2 - s1) * (t2 - t1)));
    53     }
    54     return 0;
    55 } 
    UVA11722
  • 相关阅读:
    idea插件-RestfulToolkit
    java 调试技巧
    js foreach 不能中断的现象及理解
    SpringBoot 内嵌Tomcat的默认线程配置
    SpringMVC中从doDispatch如何一步步调用到controller的方法
    干掉hao123的第n+1种方法
    查找——二叉排序树(代码超详细注释)
    为什么单螺旋桨飞机会左偏?
    【转】Python 魔法方法大全
    通俗的讲解Python中的__new__()方法
  • 原文地址:https://www.cnblogs.com/huibixiaoxing/p/8316923.html
Copyright © 2011-2022 走看看