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. myEclipse6.5与数据库(SQL Server2008)连接遇到的问题(自己总结的干货)<用SSH框架的时候,用servlet+javabean+jsp的时候>

    昨天因为学习SSH框架的搭建,时隔一年又重新遇到了myEclipse连接数据库的问题.废话不多说,上干货 (以下全部按照我遇到的问题的顺序,也就是没有顺序,就是任性) 请注意:这是在myEclipse ...

  2. 沈逸老师ubuntu速学笔记(2)-- ubuntu16.04下 apache2.4和php7结合编译安装,并安裝PDOmysql扩展

    1.编译安装apache2.4.20 第一步: ./configure --prefix=/usr/local/httpd --enable-so 第二步: make 第三步: sudo make i ...

  3. Virtualbox - 共享文件夹

    在虚拟机中添加共享文件夹——比如主机中的/home/user/download,我想把download文件夹共享给虚拟机用. 步骤:1.在虚拟机中找个挂载的目录,比如 /mnt/d,没有就新建一个目录 ...

  4. template和templateUrl区别与联系

    templateUrl其实根template功能是一样的,只不过templateUrl加载一个html文件,template后面根的是html的标签. .state('menu.about', { u ...

  5. [改善Java代码]用枚举实现工厂方法模式更简洁

    工厂方法模式(Factory Method Patter)是"创建对象的接口",让子类决定实例化哪一个类,并使一个类的实例化延迟到其子类.工厂方法模式在我们的开发工作中,经常会用到 ...

  6. 【数论,水题】UVa 11728 - Alternate Task

    题目链接 题意:给出一个数S,求一个最大的数,使这个数所有的因子之和为S; 这个所谓“因子之和”不知道有没有误导性,因为一开始以为得是素数才行.后来复习了下小学数学,比如12的因子分别是1,2,3,4 ...

  7. 【转】APP测试要点

    APP测试的时候,建议让开发打好包APK和IPA安装包,测试人员自己安装应用,进行测试.在测试过程中需要注意的测试点如下: 1.安装和卸载 ●应用是否可以在IOS不同系统版本或android不同系统版 ...

  8. 关于java.lang.NullPointerException: Module 'null' not found.的问题

    在用eclipse做struts1项目时,配置都ok了.可是一运行就报java.lang.NullPointerException: Module 'null' not found.错. 代码如下: ...

  9. Android中用PULL解析XML

    解析XML的方式有DOM,SAX,PULL,那为什么要在Android中使用PULL解析呢?首先来说一下PULL解析的优点,然后再说一下其他两种解析方式的缺点,答案就清晰可见啦. DOM不适合文档较大 ...

  10. Agile.Net 组件式开发平台 - 服务器端部署

    应用服务器: 操作系统要求推荐Windows Server 2008,服务器硬件如果支持64位建议安装64位操作系统产品以最大化发挥服务器性能. 安装操作系统Windows Server 2008,其 ...