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 ...
随机推荐
- 【原】CentOS7上安装Xwiki8.2.1
环境 CentOS 7内核版本为 3.10.0-327.el7.x86_64JDK8(jdk1.8.0_101)+Tomcat7.0.67+MySQL5.6.32XWIKI 8.2.1 xwiki- ...
- Kali+Win7双系统
----------------------------------------------------------前言---------------------------------------- ...
- centos搭建本地库
--2013年8月23日11:00:26环境:centos6.3(64bit)--场景默认情况下在用yum install 安装软件会从配置库中下载依赖包默认依赖库:来自网络在本地搭建依赖库可以节约带 ...
- Bash循环分类介绍
方法一: #!/bin/bash ` do #code here echo $i done 方法二:C语言风格 #!/bin/bash ; i<=; i++)) do printf " ...
- 关于JDK中的设计模式
结构型模式: 适配器模式: 用来把一个接口转化成另一个接口. java.util.Arrays#asList() javax.swing.JTable(TableModel) java.io.Inpu ...
- MyBatis(3.2.3) - Integration with Spring
MyBatis-Spring is a submodule of the MyBatis framework, which provides seamless integration with the ...
- 设计模式——设计模式之禅day1
单一职责 原则的定义是:应该有且仅有一个原因引起类的变更. 单一职责原则有什么好处: 类的复杂性降低,实现什么职责都有清晰明确的定义: 可读性提高,复杂性降低,那当然可读性提高了: 可维护性提高,可读 ...
- 通过读取配置文件App.config来获取数据库连接字符串
有两种方式://通过读取配置文件来获取连接字符串 第一种方式: App.config 文件的格式: <?xml version="1.0" encoding="ut ...
- 实现网页页面跳转的几种方法(meta标签、js实现、php实现)
1.meta标签实现 只需在head里加上下面这一句就行了,在当前页面停留0.1秒后跳转到目标页面 代码如下 复制代码 1 <meta http-equiv="refresh&quo ...
- java调用peoplesoft提供的webservice接口
使用到了soapui,apache-cxf,eclipse 1.使用soapui测试提供的地址有效性(如果没有soapui也可以直接在cmd命令行中使用wsdl2java命令生成客户端代码) wsdl ...