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

题意:你和朋友都要乘坐火车,为了在A城市见面,你会在时间区间[t1, t2]中的任意时刻以相同的概率密度到达,你的朋友会在时间区间[s1, s2]内的任意时刻以相同的概率密度到达,你们的火车都会在车站停留W秒,只有在同一时刻火车都在城市A的时候,才会相见,问你这件事情的概率

解题思路:建立一个直角坐标系,t1<=x<=t2 ,s1<=y<=s2这样构成的这个矩形就是所有的概率区间,然后画一条x=y的直线,然后把这个直线沿着x=y方向想下和向上平移w得到一个区间,这个区间和句型重叠的部分就是见面的概率区间,用这个面积除以矩形的面积就是见面概率,

代码如下:

 #include <stdio.h>
#include <math.h>
double s1,s2,t1,t2,w;
double area(double b)
{
double s=(t2-t1)*(s2-s1);
double y1=t1+b;
double y2=t2+b;
if(y2<=s1)  //表示直线交于矩形右下顶点或者以下 
{
//printf("y2<s1\n");
return ;
}
if(y1<=s1) //直线交于矩形下面边
{
//printf("y1<s1\n");
if(y2<=s2) //直线交于矩形右面边
{
// printf("y2<=s2\n");
return 0.5*(t2-(s1-b))*(t2+b-s1);
}
else   //直线交于矩形上面边  
{
// printf("y2>s2\n");
return 0.5*(t2-(s1-b)+t2-(s2-b))*(s2-s1);
}
}
else if(y1<=s2) // 直线交于矩形左面边 
{
//printf("y1<s2\n");
if(y2<=s2)  //直线交于矩形右面边 
{
//printf("y2<=s2\n");
return 0.5*((t1+b)-s1+(t2+b)-s1)*(t2-t1);
}
else  // 直线交于矩形上面边 
{
//printf("y2>s2\n");
return s-0.5*(s2-(t1+b))*(s2-b-t1);
} }
else
{
// printf("return s\n");
return s;
}
}
int main()
{
int t;
scanf("%d",&t);
for(int cas=; cas<=t; cas++)
{
double a,b;
scanf("%lf%lf%lf%lf%lf",&t1,&t2,&s1,&s2,&w);
a=area(w);
// printf("%lf\n",a);
b=area(-w);
//printf("%lf\n",b);
double ans=a-b;  //这里的相减是用y=x+w与矩形的下边和右边围成的面积减去y=x-w围成面积
ans/=(s2-s1)*(t2-t1);
printf("Case #%d: %.8lf\n",cas,ans);
}
return ;
}

UVA 11722的更多相关文章

  1. uva 11722 - Joining with Friend(概率)

    题目连接:uva 11722 - Joining with Friend 题目大意:你和朋友乘火车,而且都会路过A市.给定两人可能到达A市的时段,火车会停w.问说两人能够见面的概率. 解题思路:y = ...

  2. UVa 11722 (概率 数形结合) Joining with Friend

    高中也做个这种类似的题目,概率空间是[t1, t2] × [s1, s2]的矩形,设x.y分别代表两辆列车到达的时间,则两人相遇的条件就是|x - y| <= w 从图形上看就是矩形夹在两条平行 ...

  3. UVA 11722 几何概型

    第六周A题 - 几何概型 Time Limit:1000MS     Memory Limit:0KB     64bit IO Format:%lld & %llu   Descriptio ...

  4. UVa 11722 Joining with Friend (几何概率 + 分类讨论)

    题意:某两个人 A,B 要在一个地点见面,然后 A 到地点的时间区间是 [t1, t2],B 到地点的时间区间是 [s1, s2],他们出现的在这两个区间的每个时刻概率是相同的,并且他们约定一个到了地 ...

  5. uva 11722 Joining with Friend

    https://vjudge.net/problem/UVA-11722 题意:你和朋友都要乘坐火车,并且都会途径A城市.你们很想会面,但是你们到达这个城市的准确时刻都无法确定.你会在时间区间[t1, ...

  6. 集训第六周 数学概念与方法 UVA 11722 几何概型

    ---恢复内容开始--- http://acm.hust.edu.cn/vjudge/problem/viewProblem.action?id=31471 题意,两辆火车,分别会在[t1,t2],[ ...

  7. UVa 11722(几何概率)

    题意:你和你的朋友要乘坐火车,并且都会在A城市相遇,你会在(t1,t2)中的任意时刻以相同的概率密度到达, 你朋友会在(s1,s2)中的任意时刻以相同的概率密度到达,你们的火车在A城市都会停留w分钟, ...

  8. UVA - 11722 Joining with Friend 几何概率

                            Joining with Friend You are going from Dhaka to Chittagong by train and you ...

  9. KUANGBIN带你飞

    KUANGBIN带你飞 全专题整理 https://www.cnblogs.com/slzk/articles/7402292.html 专题一 简单搜索 POJ 1321 棋盘问题    //201 ...

随机推荐

  1. 产品设计原则之移动APP【转】

    随着移动互联网的发展,越来越多的Web产品开始布局移动端,因此最近经常碰到PM们在交流讨论移动APP产品的设计.我从事移动互联网已经有一年多了,通过不断的学习和实践也积累了一些心得,今天整理并分享一下 ...

  2. struts2拦截器源码分析

    前面博客我们介绍了开发struts2应用程序的基本流程(开发一个struts2的实例),通过前面我们知道了struts2实现请求转发和配置文件加载都是拦截器进行的操作,这也就是为什么我们要在web.x ...

  3. eclipse中自动生成javadoc文档

    使用eclipse生成文档(javadoc)主要有三种方法:  1,在项目列表中按右键,选择Export(导出),然后在Export(导出)对话框中选择java下的javadoc,提交到下一步.  在 ...

  4. javaweb学习总结二十一(servlet开发入门、servlet生命周期以及调用过程)

    一:servlet开发入门 servlet是sun公司一门开发动态web资源的技术,下面编写一个servlet入门程序: 1:在tomcat服务器webapps目录下新建firstServlet目录, ...

  5. 【.net】创建属于自己的log组件——改进版

    在上一篇随笔中,建立了一个自己的Log简单日志记录类   可是在众多园友的提点下,对于线程,阻塞,资源竞争等都没有仔细的去了解 在这版的改进中,我们新加了线程操作,线程等待,以及多层的错误捕获.[不知 ...

  6. (转载)运行主机管理在openvswitch之上

    在这篇文章里介绍了如果运行主机管理在openvswitch之上,而不是单独配置一个物理网卡用于主机管理,并且所有的vm的流量还是通过openvswitch走的. Running Host Manage ...

  7. C# 每天温习一点(IEnumerable<TSource>)

    1, IEnumerable<TSource> 多数屌丝写成  IEnumerable<T>  无论TSource还是T都代表一个意思:要枚举的对象的类型 .IEnumerab ...

  8. 一段C程序分析

    #include <stdio.h> #include <stdlib.h> void main() { int i; ; char ch; printf("请输入一 ...

  9. win7下的mstsc ubuntu下的rdesktop

    远程图形化登录, win7下: 开始->mstsc->10.108.103.93即可进行后续输入账号密码验证登录. 功能类似rdesktop. 如图:

  10. Xcode6模拟器时BUG导致键盘无法弹出

    Xcode 6.X版本可能会出现虚拟键盘无法调出,并在控制台出现如下提示:Can't find keyplane that supports type 5 for keyboard iPhone-Po ...