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 ...
随机推荐
- My first blog for java
我的第一个java程序: package com.hellojava; /** * @author 沽-名-钓-誉 */ public class HelloJava{ /** * @param 输出 ...
- 树莓派-基于aria2实现离线下载
安装aria2 aria2是linux下的一个下载工具,它支持http.bt种子.磁力链接三种方式下载 sudo apt-get install aria2 配置aria2 aria2支持命令参数,也 ...
- Java基础11一常用类
1.包装类 byte---java.lang.Byte char---java.lang.Character short—java.lang.Short int---java.lang.Integer ...
- mysql和eclipse连接jdbc驱动配置
环境Windows10 eclipse 64位 MySQL 一:资料准备 (MySQL,eclipse下载安装不在赘述) 配置好MySQL环境后 下载jdbc地址http://dev.mysql.co ...
- DataTable的Select()方法
DataRow[] partno = dtPack.Select("PK_SOHEAD = " + pk_sohead + " AND PART_NO = '" ...
- 我的C++笔记(Hello World)
其实在学习C++之前,是因为自己想学AI,但是发现好多AI教程都是使用C语言来进行讲解的,真心感觉到C真的计算机的基础语言行业的共同语言.至于为什么是C++,主要是C++是从C语言演变而来的,兼容C, ...
- 在maven项目结构下对于Resources目录下文件的存取
在maven项目中,文件结构如下: proj ---src ----main ----java ----Main.java ----resources ----userFile.properties ...
- MVC 入口
1.在 Global.asax public class MvcApplication : System.Web.HttpApplication { protected void Applicatio ...
- Linux系统下的 /etc/fstab 文件解读
1 [root@localhost ~]# cat /etc/fstab 2 3 # 4 # /etc/fstab 5 # Created by anaconda on Sat Nov 3 12:03 ...
- 如何指定GCC的默认头文件路径
如何指定GCC的默认头文件路径 网上偶搜得之,以之为宝:)原地址:http://blog.chinaunix.net/u/28781/showart.php?id=401631============ ...