UVA 11722
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的更多相关文章
- uva 11722 - Joining with Friend(概率)
题目连接:uva 11722 - Joining with Friend 题目大意:你和朋友乘火车,而且都会路过A市.给定两人可能到达A市的时段,火车会停w.问说两人能够见面的概率. 解题思路:y = ...
- UVa 11722 (概率 数形结合) Joining with Friend
高中也做个这种类似的题目,概率空间是[t1, t2] × [s1, s2]的矩形,设x.y分别代表两辆列车到达的时间,则两人相遇的条件就是|x - y| <= w 从图形上看就是矩形夹在两条平行 ...
- UVA 11722 几何概型
第六周A题 - 几何概型 Time Limit:1000MS Memory Limit:0KB 64bit IO Format:%lld & %llu Descriptio ...
- UVa 11722 Joining with Friend (几何概率 + 分类讨论)
题意:某两个人 A,B 要在一个地点见面,然后 A 到地点的时间区间是 [t1, t2],B 到地点的时间区间是 [s1, s2],他们出现的在这两个区间的每个时刻概率是相同的,并且他们约定一个到了地 ...
- uva 11722 Joining with Friend
https://vjudge.net/problem/UVA-11722 题意:你和朋友都要乘坐火车,并且都会途径A城市.你们很想会面,但是你们到达这个城市的准确时刻都无法确定.你会在时间区间[t1, ...
- 集训第六周 数学概念与方法 UVA 11722 几何概型
---恢复内容开始--- http://acm.hust.edu.cn/vjudge/problem/viewProblem.action?id=31471 题意,两辆火车,分别会在[t1,t2],[ ...
- UVa 11722(几何概率)
题意:你和你的朋友要乘坐火车,并且都会在A城市相遇,你会在(t1,t2)中的任意时刻以相同的概率密度到达, 你朋友会在(s1,s2)中的任意时刻以相同的概率密度到达,你们的火车在A城市都会停留w分钟, ...
- UVA - 11722 Joining with Friend 几何概率
Joining with Friend You are going from Dhaka to Chittagong by train and you ...
- KUANGBIN带你飞
KUANGBIN带你飞 全专题整理 https://www.cnblogs.com/slzk/articles/7402292.html 专题一 简单搜索 POJ 1321 棋盘问题 //201 ...
随机推荐
- 易维清使用技巧:CHM编辑利器
易维清源代码生成软件不但是一款专业的管理信息系统源代码生成器,其附带的编辑帮助信息功能更是CHM编辑利器.而且,免费试用版中的这个功能完全没有削减的哦,不花钱就可以帮你轻松编辑生成完美的CHM,官方下 ...
- js实现堆排序
<script type="text/javascript"> var arr = [22, 31, 1, 9, 99, 68, 55, 30]; function h ...
- maya 2015配置openCollada插件
1.下载对应的openCollada插件内容 https://github.com/KhronosGroup/OpenCOLLADA/wiki/OpenCOLLADA-Tools 该页面目前提供Mac ...
- Java中String类的format方法使用总结
可参考: http://www.cnblogs.com/fsjohnhuang/p/4094777.html http://kgd1120.iteye.com/blog/1293633 String类 ...
- 关于JDK中的集合总结(一)
静态方法只能继承,不能重写(Override). StringBufffer,数组,对象 都是容器. 加入数据,“zhangsan” true ,67, 三个数据数据类型不同,不能用数组作为集合,只能 ...
- hdu 4251 划分树
思路:裸的划分树 #include<iostream> #include<algorithm> #include<cstdio> #include<cmath ...
- 我眼中的go的语法特点
因为基本从c#/javascript/c/c++/python/lua/action script,一路走来,对所有的C系列的语法既熟悉又有好感: 那在看语言的时候肯定会与C系列的东西进行类比,那就总 ...
- 【转】用capability 特征加强Linux系统安全
用capability 特征加强Linux系统安全 摘要:传统UNIX系统的访问控制模型非常简单——普通用户对超级用户.在这种模型中,一个进程或者帐户要么只有很小的权限,要么具有全部的系统权限.显然, ...
- 20141015--for语句2
for语句,打印等腰三角形: 第一种方法:(使用for语句嵌套) 第二种方法:(定义string型变量) 以下是其他形状的等腰三角形: (穿插使用了for语句嵌套,定义string型)
- c# 如何处理自定义消息
C#自定义消息通信往往采用事件驱动的方式实现,但有时候我们不得不采用操作系统的消息通信机制,例如在和底层语言开发的DLL交互时,是比较方便的.下面列举了一些实现方式,供大家参考:一.通过SendMes ...