UVA 11722 几何概型
Time Limit:1000MS Memory Limit:0KB 64bit IO Format:%lld & %llu
Description
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
题解:给你两辆火车的到达时间的区间【t1-t2】【s1-s2】,到达后停留时间为w分钟,求坐这两辆火车的人相遇的概率
求概率的问题,要用到线性规划,不然很难解决
如果t2+w<s1的话说明无论如何不可能相遇
然后有四种情况,y=x+w, y=x-w可直接代入-w
#include<iostream>
#include<cstdio>
using namespace std;
double t1,s1,t2,s2,w;
double juge(double ww)
{
double s=(t2-t1)*(s2-s1);
if(t2+ww<s1)
return ;
if(t1+ww<=s1)
{
if(t2+ww<=s2)
return 0.5*(t2+ww-s1)*(t2+ww-s1); //
else
return 0.5*(t2+ww-s2+t2+ww-s1)*(s2-s1); //
}
if(t1+ww<s2)
{
if(t2+ww<=s2)
return 0.5*(t2-t1)*(t2+ww-s1+t1+ww-s1); //
else
return s-0.5*(s2-ww-t1)*(s2-ww-t1); //
}
else return s;
}
int main()
{
int t,k=;
cin>>t;
while(t--)
{
cin>>t1>>t2>>s1>>s2>>w;
double yinying=juge(w)-juge(-w);
yinying/=(t2-t1)*(s2-s1);
printf("Case #%d: %.8lf\n",k++,yinying);
}
}
UVA 11722 几何概型的更多相关文章
- 集训第六周 数学概念与方法 UVA 11722 几何概型
---恢复内容开始--- http://acm.hust.edu.cn/vjudge/problem/viewProblem.action?id=31471 题意,两辆火车,分别会在[t1,t2],[ ...
- Codeforces - 77B - Falling Anvils - 几何概型
https://codeforc.es/contest/77/problem/B 用求根公式得到: \(p-4q\geq0\) 换成熟悉的元: \(y-4x\geq0\) 其中: \(x:[-b,b] ...
- 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 ...
- 数学概念——A 几何概型
You are going from Dhaka to Chittagong by train and you came to know one of your old friends is goin ...
- 几何概型 uva11722
#include<bits/stdc++.h> using namespace std; int t1,t2,s1,s2,w; int get(int b) { ; int d=s2-s1 ...
- 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 从图形上看就是矩形夹在两条平行 ...
随机推荐
- 如何下载coursera视频
国内观看Coursera非常卡顿,经常播放到一半就卡死了,不知道什么原因.因此只能想办法下载下来之后再看. Github上有一个脚本点击打开链接,提供整门课程的下载服务.用着还是非常方便的,使用方法如 ...
- 初识AM335X
TI 的AM335X,linux 操作系统,全都是陌生的东东,一点一点来熟悉吧. 拿的TI代理的一开发板,直接看文档.环境由于之前一同事已经装好了,公司条件受限,没法让我们一人一台ubuntu的机子来 ...
- 《HTML5 从入门到精通--7.6.3 单元格垂直跨度——rowspan》
单元格除了能够在水平方向上跨列,还能够垂直方向上跨行.跨行设置须要使用rowspan參数. 语法 <td rowspan="单元格跨行数"> 语法解释 与水平跨度相相应 ...
- CSU1661: Query Mutiple
Description One day,Little-Y saw many numbers standing in a row. A question suddenly appeared in her ...
- VIPServer VS LVS
http://www.cnblogs.com/nanyangzp/p/5552725.html
- wpf的学习日志(二)
window演示基础(windows presentation Foundation)用于windowsw图形显示系统 InitializeComponent()方法的工作就是system.windo ...
- call()与apply()区别
一.方法的定义 call方法: 语法:call(thisObj,Object)定义:调用一个对象的一个方法,以另一个对象替换当前对象.说明:call 方法可以用来代替另一个对象调用一个方法.call ...
- CSS从大图中抠取小图完整教程(background-position应用) (转)
自认为把background-position的应用讲得非常通俗易懂的教材.做个记号. 相信很多喜欢研究网页界面的童鞋都遇到过一个奇妙的现象:网页中很多图片素材被合成在一张图片上. 起初小菜模仿网站的 ...
- 【转】Java学习之Iterator(迭代器)的一般用法 (转)
[转]Java学习之Iterator(迭代器)的一般用法 (转) 迭代器(Iterator) 迭代器是一种设计模式,它是一个对象,它可以遍历并选择序列中的对象,而开发人员不需要了解该序列的底层结构.迭 ...
- 解决 oracle 错误ORA-01033
数据库在导入数据的过程中,意外关机.重启机器后,pl/sql-developer不能登录数据库,报错ORA-01033:oracle initializationor shutdown in prog ...