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 从图形上看就是矩形夹在两条平行 ...
随机推荐
- Nodejs in Visual Studio Code 13.构建单页应用Scrat示例挖一挖
1.开始 Scrat作者说要搞个很碉堡的示例,果然就搞出来了,如果要学习并使用Scrat,可以从官方示例开始,简直太方便了. 2.Scrat示例 目录 component_modules : 公共组件 ...
- 动软代码生成器 可用于生成Entity层,可更改模板 /codesmith 也可以
动软代码生成器官方下载地址:http://www.maticsoft.com/download.aspx 教程:http://jingyan.baidu.com/article/219f4bf7dfd ...
- poj1013
题目大意:假造的银币 Sally Jones有一些游客给的银币,但是只有11枚是真正的银币(有一枚是假的),从颜色和大小是无法区分真比还是假币的,但是它的重量和真币是不同的,Sally Jones它是 ...
- PHP实现大文件的上传设置
打开php.ini,首先找到 ;;;;;;;;;;;;;;;; ; File Uploads ; ;;;;;;;;;;;;;;;; 区域,有影响文件上传的以下几个参数: file_uploads = ...
- redis 集群
http://www.linuxidc.com/Linux/2015-08/121845.htm Redis3.0版本之后支持Cluster,具体介绍redis集群我就不多说,了解请看redis中文简 ...
- lesson10:hashmap变慢原因分析
下面的英文描述了String.hashCode()方法,在特定情况下,返回值为0的问题: Java offers the HashMap and Hashtable classes, which us ...
- java.lang.NoClassDefFoundError: com/ibatis/sqlmap/engine/mapping/result/BasicResultMap
错误日志: java.lang.NoClassDefFoundError: com/ibatis/sqlmap/engine/mapping/result/BasicResultMap at ...
- [Ruby] Ruby Variable Scope
Scope defines where in a program a variable is accessible. Ruby has four types of variable scope, lo ...
- 使用XStream注解实现Java对象与XML互相转换的代码示例
本文记录一下使用xstream这个api的注解特性对Java对象与XML字符串相互转换的一些代码示例. 我们很多人都处理过XML文件,也有很多非常成熟的第三方开源软件.如:jdom.dom4j等 ...
- Android的Touch系统简介(一)
一.Android touch事件的相关概念 用户的Touch事件被包装成MotionEvent 用户当前的touch事件主要类型有: ACTION_DOWN: 表示用户开始触摸. ACTION_MO ...