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 几何概率的更多相关文章

  1. UVa 11722 Joining with Friend (几何概率 + 分类讨论)

    题意:某两个人 A,B 要在一个地点见面,然后 A 到地点的时间区间是 [t1, t2],B 到地点的时间区间是 [s1, s2],他们出现的在这两个区间的每个时刻概率是相同的,并且他们约定一个到了地 ...

  2. uva 11722 - Joining with Friend(概率)

    题目连接:uva 11722 - Joining with Friend 题目大意:你和朋友乘火车,而且都会路过A市.给定两人可能到达A市的时段,火车会停w.问说两人能够见面的概率. 解题思路:y = ...

  3. uva 11722 Joining with Friend

    https://vjudge.net/problem/UVA-11722 题意:你和朋友都要乘坐火车,并且都会途径A城市.你们很想会面,但是你们到达这个城市的准确时刻都无法确定.你会在时间区间[t1, ...

  4. UVa 11722 (概率 数形结合) Joining with Friend

    高中也做个这种类似的题目,概率空间是[t1, t2] × [s1, s2]的矩形,设x.y分别代表两辆列车到达的时间,则两人相遇的条件就是|x - y| <= w 从图形上看就是矩形夹在两条平行 ...

  5. UVa 11722(几何概率)

    题意:你和你的朋友要乘坐火车,并且都会在A城市相遇,你会在(t1,t2)中的任意时刻以相同的概率密度到达, 你朋友会在(s1,s2)中的任意时刻以相同的概率密度到达,你们的火车在A城市都会停留w分钟, ...

  6. UVA 11722

    You are going from Dhaka to Chittagong by train and you came to know one of your old friends is goin ...

  7. UVA 11722 几何概型

    第六周A题 - 几何概型 Time Limit:1000MS     Memory Limit:0KB     64bit IO Format:%lld & %llu   Descriptio ...

  8. 集训第六周 数学概念与方法 UVA 11722 几何概型

    ---恢复内容开始--- http://acm.hust.edu.cn/vjudge/problem/viewProblem.action?id=31471 题意,两辆火车,分别会在[t1,t2],[ ...

  9. KUANGBIN带你飞

    KUANGBIN带你飞 全专题整理 https://www.cnblogs.com/slzk/articles/7402292.html 专题一 简单搜索 POJ 1321 棋盘问题    //201 ...

随机推荐

  1. HIT Software Construction Lab6引发出来对锁的问题的探究

    前言 做完lab5开始做lab6了鸭,哈工大计算机学院的学生永不停歇.在做lab6的时候,我在想移动猴子是锁一整个ladder(ADT)还是只锁一个ladder的一个域Monkey数组呢?这两个好像差 ...

  2. eclipse中文汉字看不清或过小的问题解决方法!!

    把字体修改为 中欧字体就可以看清汉字

  3. SSRS 报表 如何加参数

    SSRS 报表 如何加参数 连接上以后出现一个问题 就是给报表加上参数以后报表不断刷新,跟上次那个报表刷新是同样的问题.那么下面我们来解决一下. 1. 这是给报表添加默认参数进入页面后就不断的刷新刷新 ...

  4. (转)redux

    随着 JavaScript 单页应用开发日趋复杂,越来越多的 state (状态)需要在前端进行管理. 这些 state 可能包括服务器响应.缓存数据.本地生成尚未持久化到服务器的数据,也包括 UI ...

  5. MyEclipse 中的一些快捷键

    @import url(/css/cuteeditor.css); ------------------------------------- MyEclipse 快捷键1(CTRL) ------- ...

  6. Approximate Nearest Neighbors.接近最近邻搜索

    (一):次优最近邻:http://en.wikipedia.org/wiki/Nearest_neighbor_search 有少量修改:如有疑问,请看链接原文.....1.Survey:Neares ...

  7. IE兼容opacity

    filter:alpha(opacity=80); opacity: 0.57; /* Firefox, Safari(WebKit), Opera) filter: "alpha(opac ...

  8. Vim 插件管理及安装

    1.先将ubuntu1204的软件源进行更新.sudo apt-get update 2.再在终端中敲如下命令,让程序自动安装,根据网速的好坏安装时间有长有短. wget -qO- https://r ...

  9. 洛谷P3807 【模板】卢卡斯定理_组合数学模板

    Code: #include<cstdio> using namespace std; typedef long long LL; const int maxn=1000000+2; LL ...

  10. Linux下清空文件的几种方法

    $ : > filename $ > filename $ echo "" > filename $ echo > filename $ cat /dev/ ...