UVA - 11722 Joining with Friend 几何概率
Joining with Friend
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
题意:
:
讨论就是了
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <algorithm>
using namespace std ;
typedef long long ll; const int N=; double sum,s1,s2,t1,t2,w;
double cal(double k) {
double ans = ;
if(s2 > t2 + k && s1 > t1 + k) {
double tmp = t2 + k - s1;
tmp = tmp < ? : tmp;
ans = sum - (tmp) * (tmp) / 2.0;
}
else if(s2 > t2 + k) {
double l = s2 - (t1 + k);
double r = s2 - (t2 + k) + l;
ans = r * (t2 - t1) / 2.0;
}
else if(s1 > t1 + k) {
double l = s2 - k -t1;
double r = s1 - k -t1 + l;
ans = r * (s2 - s1) / 2.0;
}
else {
double tmp = s2 - k - t1;
tmp = tmp < ? : tmp;
ans = tmp * tmp / 2.0;
}
if(k < ) ans = sum - ans;
return ans;
}
int main() {
int T, cas = ;
scanf("%d",&T);
while(T--) {
scanf("%lf%lf%lf%lf%lf",&t1,&t2,&s1,&s2,&w);
sum = 1.0 * (s2 - s1) * (t2 - t1) ;
double ans = cal(w) + cal(-w);
printf("Case #%d: %.6f\n", cas++, - ans * 1.0 / sum);
}
return ;
}
代码


UVA - 11722 Joining with Friend 几何概率的更多相关文章
- UVa 11722 Joining with Friend (几何概率 + 分类讨论)
题意:某两个人 A,B 要在一个地点见面,然后 A 到地点的时间区间是 [t1, t2],B 到地点的时间区间是 [s1, s2],他们出现的在这两个区间的每个时刻概率是相同的,并且他们约定一个到了地 ...
- uva 11722 - Joining with Friend(概率)
题目连接:uva 11722 - Joining with Friend 题目大意:你和朋友乘火车,而且都会路过A市.给定两人可能到达A市的时段,火车会停w.问说两人能够见面的概率. 解题思路:y = ...
- uva 11722 Joining with Friend
https://vjudge.net/problem/UVA-11722 题意:你和朋友都要乘坐火车,并且都会途径A城市.你们很想会面,但是你们到达这个城市的准确时刻都无法确定.你会在时间区间[t1, ...
- UVa 11722 (概率 数形结合) Joining with Friend
高中也做个这种类似的题目,概率空间是[t1, t2] × [s1, s2]的矩形,设x.y分别代表两辆列车到达的时间,则两人相遇的条件就是|x - y| <= w 从图形上看就是矩形夹在两条平行 ...
- UVa 11722(几何概率)
题意:你和你的朋友要乘坐火车,并且都会在A城市相遇,你会在(t1,t2)中的任意时刻以相同的概率密度到达, 你朋友会在(s1,s2)中的任意时刻以相同的概率密度到达,你们的火车在A城市都会停留w分钟, ...
- UVA 11722
You are going from Dhaka to Chittagong by train and you came to know one of your old friends is goin ...
- UVA 11722 几何概型
第六周A题 - 几何概型 Time Limit:1000MS Memory Limit:0KB 64bit IO Format:%lld & %llu Descriptio ...
- 集训第六周 数学概念与方法 UVA 11722 几何概型
---恢复内容开始--- http://acm.hust.edu.cn/vjudge/problem/viewProblem.action?id=31471 题意,两辆火车,分别会在[t1,t2],[ ...
- KUANGBIN带你飞
KUANGBIN带你飞 全专题整理 https://www.cnblogs.com/slzk/articles/7402292.html 专题一 简单搜索 POJ 1321 棋盘问题 //201 ...
随机推荐
- POJ 3258 (NOIP2015 D2T1跳石头)
河中跳房子 总时间限制: 1000ms 内存限制: 65536kB 描述 每年奶牛们都要举办各种特殊版本的跳房子比赛,包括在河里从一个岩石跳到另一个岩石.这项激动人心的活动在一条长长的笔直河道中进行, ...
- [hihocoder][Offer收割]编程练习赛49
相似颜色 #pragma comment(linker, "/STACK:102400000,102400000") #include<stdio.h> #includ ...
- layui新手使用
1,首先最重要的是引入官方的layui.js layui.css文件 2,在自己的项目中新建一个目录 再在该目录下建一个js文件,js中写入 layui.define(['layer', 'form ...
- 【Oracle】创建角色
任务:创建角色 1)创建角色sse_role,授予create session 权限 2)创建角色tblo_role,授予CREATE PROCEDURE, CREATE SEQUENCE, CREA ...
- aes加密算法的一个问题
百度“delphi aes”出来的结果,千篇一律,都是相互转载,但是没有人发现EldoS, Alexander Ionov于1998-2001写的ElAes.pas代码,存在一个问题. 相同的key和 ...
- spring boot的项目名称问题
spring boot直接执行main函数时是不需要加项目名称,但是可以在application配置文件中配置server.context-path=/*来配置项目名称: spring mvc的运行方 ...
- (转)RabbitMQ学习之spring整合发送异步消息(注解实现)
http://blog.csdn.net/zhu_tianwei/article/details/40919249 实现使用Exchange类型为DirectExchange. routingkey的 ...
- 常用 CSS 选择器
// css 读取顺序从右到左,符合要求的都会匹配 // 通配符选择器 -- 选择所有元素 * // 通配符选择器 -- 选择某个元素下的所有元素 .demo * // 元素选择器 html,body ...
- 【airtest】iOS,Android 依托 jenkins 并行跑
Airtest 只支持一台mac 连接一台iPhone, 以下方法是以“一台mac 连接一台iPhone”为基础,依托jenkins 统一管理多台iPhone. [mac] jenkins mast ...
- Project Euler 48 Self powers( 大数求余 )
题意: 项的自幂级数求和为 11 + 22 + 33 + - + 1010 = 10405071317. 求如下一千项的自幂级数求和的最后10位数字:11 + 22 + 33 + - + 100010 ...