UVA-11722 joining with Friend geometry probability

Source: Internet
Author: User

Joining with Friend

Going from Dhaka to Chittagong by train and you came to know one of the your old friends is going
From city Chittagong to Sylhet. You also know that both the trains would 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 is not? Xed. In fact your train can
Reach in any time within the interval [T1, T2] with equal probability. The other one would reach in any
Time within the interval [S1, S2] with equal probability. Each of the trains would stop for W minutes after
Reaching the junction. You can only see your friend, if in some time both of the trains are present in the
Station. Find the probability that's can see your friend.
Input
The. RST line of input would denote the number of cases T (T < 500). Each of the following T-line would
Contain 5 integers t1, t2, S1, S2, W (360≤t1 < T2 < 1080, 360≤s1 < S2 < and 1≤w≤90). All
Inputs T1, T2, S1, S2 and W is given in minutes and T1, T2, S1, S2 is 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. 1e−6 error in your output would 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

Test instructions

Just talk.

#include <iostream>#include<cstdio>#include<cmath>#include<cstring>#include<algorithm>using namespacestd; typedefLong Longll;Const intn=10000;Doublesum,s1,s2,t1,t2,w;DoubleCalDoublek) {DoubleAns =0; if(S2 > t2 + k && S1 > T1 +k) {DoubleTMP = t2 + K-S1; TMP= tmp <0?0: tmp; Ans= Sum-(TMP) * (TMP)/2.0; }    Else if(S2 > t2 +k) {DoubleL = S2-(t1 +k); Doubler = S2-(t2 + k) +l; Ans= R * (T2-T1)/2.0; }    Else if(S1 > T1 +k) {DoubleL = s2-k-T1; Doubler = S1-k-t1 +l; Ans= R * (S2-S1)/2.0; }    Else {        DoubleTMP = S2-k-T1; TMP= tmp <0?0: tmp; Ans= TMP * TMP/2.0; }    if(K <0) ans = sum-ans; returnans;}intMain () {intT, 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); Doubleans = cal (W) + CAL (-W); printf ("Case #%d:%.6f\n", cas++,1-ans *1.0/sum); }    return 0;}
Code

UVA-11722 joining with Friend geometry probability

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.