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 ...
随机推荐
- bootstrap与jQuery结合的动态进度条
此款进度条实现的功能: 1.利用了bootstrap的进度条组件. a.在最外层的<div>中加入class .progress,在里层<div>加入class .progre ...
- Github 团队协作基本流程与命令操作 图解git工作流程
# 先 fork 项目到自己 github # 1. 从自己仓库克隆到本地(clone 的是项目指定的默认分支,比如 master) git clone git@github.com:me/em.gi ...
- PhotoZoom Pro 7 支持哪些图像格式?
PhotoZoom是一款新颖的.技术上具有革命性的对数码图片无损放大的工具.为设计工作者提供了优良的解决方案,可快速渲染出完美的放大照片,呈现无与伦比的画质效果.将因其应用的广泛性,所以对图像文件的支 ...
- 文字横向滚动marquee
<div style="width:200px; height:300px"> <marquee behavior="scroll" cont ...
- xshell 连接 ubuntu 16.04报错
outgoing encryption 错误 使用xshell和xftp连接 ubuntu 16.04 时出现找不到匹配的 outgoing encryption 算法的错误提示. 问题阐述: 在 ...
- 四种ASP网页跳转代码
时间:2012-06-12 21:12来源:未知 输入:铜都风尘 点击: 32987 次 如果你要在服务器端跳转,可以这样: Response.Redirect(http://blog.163.com ...
- IOS - 零碎
---恢复内容开始--- 1.模拟器目录: ProjectNameApk.documents.library(cache.preference.cookies).temp 2.Edit-Refacto ...
- Project Euler 38 Pandigital multiples
题意: 将192分别与1.2.3相乘: 192 × 1 = 192192 × 2 = 384192 × 3 = 576 连接这些乘积,我们得到一个1至9全数字的数192384576.我们称192384 ...
- luogu 4240 毒瘤之神的考验 (莫比乌斯反演)
题目大意:略 题面传送门 果然是一道神duliu题= = 出题人的题解传送门 出题人的题解还是讲得很明白的 1.关于$\sum\limits_{i=1}^{n}\sum\limits_{j=1}^{m ...
- [SCOI2010] 股票交易 (单调队列优化dp)
题目描述 最近lxhgww又迷上了投资股票,通过一段时间的观察和学习,他总结出了股票行情的一些规律. 通过一段时间的观察,lxhgww预测到了未来T天内某只股票的走势,第i天的股票买入价为每股APi, ...