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 ...
随机推荐
- [luogu普及] ---P1032 字串变换
目的 刷完100AC (最近很不舒服,写博客耗时啊 记录第一个字符串的题目 参考 https://www.luogu.org/blog/user20197/solution-p1032 代码 #inc ...
- 你必须知道的.net导航
http://www.cnblogs.com/anytao/archive/2007/09/14/must_net_catalog.html
- pinpoint体系中,关于如何清理过期hbase数据
版本: pinpoint:1.7.1 hbase:1.2.6 命令行命令: $HBASE_HOME/bin/hbase shell newrestruct.hbase 备注:保留一天半的数据(秒 ...
- [] == ![]为什么是true
我们先来考虑这个问题,console.log([] == false)会打印什么呢? 答案是true.为什么呢? 首先,因为当"=="号两边其中一个是布尔值的话,先把它转换为数字( ...
- Oracle表的种类及定义
1表的类型 1)堆组织表(heap organized tables). 当增加数据时,将使用在段中找到的第一个适合数据大小的空闲空间.当数据从表中删除时,留下的空间允许随后的insert和updat ...
- CGContext与上下文
上下文指的是场景拥有的资源或属性. 上下文的操作包含上下文的设置: 和上下文的引用. 上下文是一个结构体. 主要包含结构体的设置和使用.
- map 解析
Observable.of(1, 2, 3) .map { $0 * $0 } .subscribe(onNext: { print($0) }) .disposed(by: disposeBag) ...
- win系统如何在桌面显示我的电脑
如果是在Windows Server 2012本地控制台下,直接按Win(键盘上的微软徽标键)+R,输入: rundll32.exe shell32.dll,Control_RunDLL desk.c ...
- Unity3D_脚本_获取对象的位置_碰撞后加一段音乐_旋转对象_使物体随机运动
获取对象的位置(Position) 在代码中加上 public Rigidbody cd;cd = GetComponent<Rigidbody>();Vector3 m=cd.trans ...
- python的jieba分词
# 官方例程 # encoding=utf-8 import jieba seg_list = jieba.cut("我来到北京清华大学", cut_all=True) print ...