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. 关于Eclipse(MyEclipse)中一次性批量导入多个项目Project.

    以前更换Eclipse(MyEclipse)的时候要想把原Eclipse中的项目导入到新的Eclipse中的做法是: 1.先把原Eclipse中工作空间中的项目(不包括.metadata文件夹)复制到 ...

  2. OSI七层模型:TCP/IP && HTTP && WebSocket && MQTT

    OSI七层模型分为 物理层:  建立.维护.断开物理连接 处理bit流 数据链路层,将比特组合成字节进而组合成帧,用MAC地址访问介质,错误发现但不能纠正 处理数据帧 Frame 网络层,进行逻辑地址 ...

  3. 微信小程序(原名微信应用号)开发工具0.9版安装教程

    微信小程序全称微信公众平台·小程序,原名微信公众平台·应用号(简称微信应用号) 声明 微信小程序开发工具类似于一个轻量级的IDE集成开发环境,目前仅开放给了少部分受微信官方邀请的人士(据说仅200个名 ...

  4. pre 随变化的样式

    <pre style="white-space: pre-wrap;white-space: -moz-pre-wrap;white-space: -pre-wrap;white-sp ...

  5. MyBatis(3.2.3) - Configuring MyBatis using XML, Settings

    The default MyBatis global settings, which can be overridden to better suit application-specific nee ...

  6. Git CMD - diff: Show changes between commits, commit and working tree, etc

    命令格式 git diff [options] [<commit>] [--] [<path>…​] git diff [options] --cached [<comm ...

  7. 如何将 select top 4 id from table1 赋值 给 declare @id1 int,@id2 int,@id3 int,@id4 int

    declare @id1 int,@id2 int,@id3 int,@id4 int ),) select @sickcode = sickcode,@sfrq =sfrq from tablena ...

  8. 禁用iOS9 App Transport Security(ATS)特性时不起作用

    iOS 9发布后,原来开发的iPad应用在iOS9下面测试时,协议使用的是HTTP,发送网络请求时,Console窗口输出: App Transport Security has blocked a ...

  9. docker & nodejs

    Docker 部署 Node js demo程序 1.准备node js程序,使用express框架. mkdir demo 在demo文件夹下建立package.json { "name& ...

  10. css3学习笔记之用户界面

    CSS3 调整尺寸(Resizing) CSS3中,resize属性指定一个元素是否应该由用户去调整大小. 这个 div 元素由用户调整大小. (在 Firefox 4+, Chrome, 和 Saf ...