数学概念——A 几何概型
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 midnight00: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 |
Output for Sample Input |
2 1000 1040 1000 1040 20 720 750 730 760 16 |
Case #1: 0.75000000 Case #2: 0.67111111 |
解题思路:
题意:你和朋友都要乘坐火车,为了在A城市见面,你会在时间区间[t1, t2]中的任意时刻以相同的概率密度到达,你
的朋友会在时间区间[s1, s2]内的任意时刻以相同的概率密度到达,你们的火车都会在车站停留W秒,
只有在同一时刻火车都在城市A的时候,才会相见,问你这件事情的概率
思路:将密度构造成矩形,然后求解y = x +(-) b围成的图形占矩阵面积的大小,分情况讨论
程序代码:
#include <cstdio>
using namespace std;
double t1,t2,s1,s2;
double cal(double w)
{
double x1=s1-w,x2=s2-w,y1=t1+w,y2=t2+w;
if(y1>=s2) return ;
if(y2<=s1) return(t2-t1)*(s2-s1);
bool l=(y1>=s1&&y1<=s2);
bool r=(y2>=s1&&y2<=s2);
bool u=(x2>=t1&&x2<=t2);
bool d=(x1>=t1&&x1<=t2);
if(l&&u) return (x2-t1)*(s2-y1)*0.5;
if(l&&r) return (s2-y1+s2-y2)*(t2-t1)*0.5;
if(d&&u) return (x2-t1+x1-t1)*(s2-s1)*0.5;
if(d&&r) return (t2-t1)*(s2-s1)-(t2-x1)*(y2-s1)*0.5;
}
int main()
{
int Case=,t;
double w;
scanf("%d",&t);
while(t--)
{
scanf("%lf%lf%lf%lf%lf",&t1,&t2,&s1,&s2,&w);
printf("Case #%d: %.7lf\n",++Case,(cal(-w)-cal(w))/(t2-t1)/(s2-s1));
}
return ;
}
数学概念——A 几何概型的更多相关文章
- UVA 11722 几何概型
第六周A题 - 几何概型 Time Limit:1000MS Memory Limit:0KB 64bit IO Format:%lld & %llu Descriptio ...
- Codeforces - 77B - Falling Anvils - 几何概型
https://codeforc.es/contest/77/problem/B 用求根公式得到: \(p-4q\geq0\) 换成熟悉的元: \(y-4x\geq0\) 其中: \(x:[-b,b] ...
- 集训第六周 数学概念与方法 UVA 11722 几何概型
---恢复内容开始--- http://acm.hust.edu.cn/vjudge/problem/viewProblem.action?id=31471 题意,两辆火车,分别会在[t1,t2],[ ...
- 几何概型 uva11722
#include<bits/stdc++.h> using namespace std; int t1,t2,s1,s2,w; int get(int b) { ; int d=s2-s1 ...
- UVa 11971 - Polygon(几何概型 + 问题转换)
链接: https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem& ...
- UVa 11346 - Probability(几何概型)
链接: https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem& ...
- UVA 11346 Probability (几何概型, 积分)
题目链接:option=com_onlinejudge&Itemid=8&page=show_problem&problem=2321">https://uva ...
- Math concepts / 数学概念
链接网址:Math concepts / 数学概念 – https://www.codelast.com/math-concepts-%e6%95%b0%e5%ad%a6%e6%a6%82%e5%bf ...
- 21副GIF动图让你了解各种数学概念
baidu 21副GIF动图让你了解各种数学概念
随机推荐
- TOM大师脚本-show space 多个版本,谢谢大牛们
示例一 该脚本需区分 对象的管理方式是 自动还是 手动, 对手动管理方式 的表显示很全面 SQL> exec show_space_old('MAN_TAB','DEV','TABLE'); F ...
- 关于C#与.NET Framework
前几天,有一个做测试的问我.NET Framework是什么,和C#是什么关系呢. 下面我就来解释一下.NET Framework是什么:.NET Framework是一个框架,是应用程序运行时所需要 ...
- 十二、C# 委托与Lambda表达式(匿名方法的另一种写法)
委托与Lambda表达式 1.委托概述 2.匿名方法 3.语句Lambda 4.表达式Lambda 5.表达式树 一.委托概述 相当于C++当中的方法指针,在C#中使用delegate 委托来 ...
- 【POJ2887】【块状链表】Big String
Description You are given a string and supposed to do some string manipulations. Input The first lin ...
- coffee 编译时, 用本地环境
export PATH="./node_modules/.bin:$PATH" 原文: How to use package installed locally in node_m ...
- [转] 使用CSS3 will-change提高页面滚动、动画等渲染性能 ---张鑫旭
一.先来看一个例子 下面这个例子来自某外文,我这里简单转述下. 视差滚动现在不是挺流行的嘛,然后Chris Ruppel当其使用background-attachment: fixed实现背景图片不随 ...
- 支付宝支付错误 系统忙:错误代码AE150002999
今天出现支付宝支付错误,支付系统繁忙请稍等,错误码AE150002999.测试了其他连个收款方,可跳转到正常扫码支付页面,排除了代码错误. 在登录支付宝商家中,也签约了“即时到帐”功能.度娘和查看都找 ...
- 浏览器中的WebSocket("ws://127.0.0.1:9988");
<script type="text/javascript"> function WebSocketTest() { if ("WebSocket" ...
- mysql数据类型——TEXT和Blob
TEXT是 以文本方式存储的,如果存储英文的话区分大小写 Blob是以二进制方式存储的,不区分大小写. xxxBlob存储的数据只能整体读出 有4种text类型:tinytext.text.medi ...
- 总结几种C#窗体间通讯的处理方法
摘要:本文介绍了C#窗体间通讯的几种处理方法,即传值.继承.事件回调,希望对大家有用. http://www.cnblogs.com/jara/p/3439603.html 应用程序开发中,经常需要多 ...