题目连接:uva 11722 - Joining with Friend

题目大意:你和朋友乘火车,而且都会路过A市。给定两人可能到达A市的时段,火车会停w。问说两人能够见面的概率。

解题思路:y = x + w 和y = x - w在给定时间内围成的面积除以时间的总面积,就是求面积的时候要分情况处理。

#include <cstdio>
#include <cstring>
#include <algorithm> using namespace std;
int t1, t2, s1, s2, w;
double sum; double solve (int k) { double ret = 0; if (s2 > t2 + k && s1 > t1 + k) { double r = max(t2 + k - s1, 0);
ret = sum - r * r / 2;
} else if (s2 > t2 + k) { double r = 2 * s2 - t1 - t2 - 2 * k;
ret = r * (t2 - t1) / 2;
} else if (s1 > t1 + k) { double r = s2 + s1 - 2 * k - 2 * t1;
ret = r * (s2 - s1) / 2;
} else { double r = max(s2 - k - t1, 0);
ret = r * r / 2;
} if (k < 0)
ret = sum - ret;
return ret;
} int main () {
int cas;
scanf("%d", &cas);
for (int kcas = 1; kcas <= cas; kcas++) {
scanf("%d%d%d%d%d", &t1, &t2, &s1, &s2, &w); sum = 1.0 * (t2 - t1) * (s2 - s1);
double ans = solve(w) + solve(-w);
printf("Case #%d: %.8lf\n", kcas, 1 - ans / sum);
}
return 0;
}

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

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

  3. UVA - 11722 Joining with Friend 几何概率

                            Joining with Friend You are going from Dhaka to Chittagong by train and you ...

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

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

  5. UVa 10491 Cows and Cars (概率&广义三门问题 )

    10491 - Cows and Cars Time limit: 3.000 seconds http://uva.onlinejudge.org/index.php?option=com_onli ...

  6. [uva 11762]Race to 1[概率DP]

    引用自:http://hi.baidu.com/aekdycoin/item/be20a91bb6cc3213e3f986d3,有改动 题意: 已知D, 每次从[1,D] 内的所有素数中选择一个Ni, ...

  7. UVA 10828 - Back to Kernighan-Ritchie(概率+高斯消元)

    UVA 10828 - Back to Kernighan-Ritchie 题目链接 题意:给图一个流程图,有结点的流程,每次进入下一个流程概率是均等的,有q次询问,求出每次询问结点的运行期望 思路: ...

  8. UVA 11427 - Expect the Expected(概率递归预期)

    UVA 11427 - Expect the Expected 题目链接 题意:玩一个游戏.赢的概率p,一个晚上能玩n盘,假设n盘都没赢到总赢的盘数比例大于等于p.以后都不再玩了,假设有到p就结束 思 ...

  9. uva 11427 - Expect the Expected(概率)

    题目链接:uva 11427 - Expect the Expected 题目大意:你每天晚上都会玩纸牌,每天固定最多玩n盘,每盘胜利的概率为p,你是一个固执的人,每天一定要保证胜局的比例大于p才会结 ...

随机推荐

  1. Decoding BASE64 in ABAP

    Code Gallery Decoding BASE64 in ABAP Skip to end of metadata Created by Frank Klausner, last modifie ...

  2. springboot 开发入门,及问题汇总

    1 . springboot简单介绍(http://projects.spring.io/spring-boot/) 现在的web项目几乎都会用到spring框架,而要使用spring难免需要配置大量 ...

  3. Centos系统各种日志存详解

    Centos系统各种日志存储路径和详细介绍 Linux常见的日志文件详述如下 1./var/log/boot.log(自检过程) 2./var/log/cron (crontab守护进程crond所派 ...

  4. VS2008下编译BOOST 1.39的ASIO库

    由于全部编译BOOST库需要的时间太长,而且耗费空间,况且我只需要用ASIO库,所以就没有必要全部编译了. boost库到www.boost.org上下载. 编译很简单,假设你的boost存放的目录是 ...

  5. jquery mobile 对手势触控提供了如下几个事件监听:

    jquery mobile 对手势触控提供了如下几个事件监听: 复制代码代码如下: tap  当用户点屏幕时触发taphold 当用户点屏幕且保持触摸超过1秒时触发swipe 当页面被垂直或者水平拖动 ...

  6. jsp:setProperty

    类声明: package test; public class Student {     private int age; public int getAge() {         return ...

  7. HDU 5045(Contest-费用流)[template:费用流]

    Contest Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others) Total Submi ...

  8. C/C++中char* 与char []定义的区别

    转载请注明来自souldak,微博:@evagle Question: 给你一个字符串例如abb输出它包含的字符的所有可能排列. 例如abb输出3个:abb,bab,bba Answer: 假设我们自 ...

  9. Eclipse扩展点

    ~~ org.eclipse.ui.actionSets(IWorkbenchWindowActionDelegate)||  org.eclipse.ui.commands 这两个扩展点都是对菜单进 ...

  10. linux运维常用命令集

    1.删除0字节文件 find -type f -size 0 -exec rm -rf {} \;   2.查看进程 按内存从大到小排列 PS -e   -o "%C   : %p : %z ...