UVA 11722 几何概型
Time Limit:1000MS Memory Limit:0KB 64bit IO Format:%lld & %llu
Description
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
题解:给你两辆火车的到达时间的区间【t1-t2】【s1-s2】,到达后停留时间为w分钟,求坐这两辆火车的人相遇的概率
求概率的问题,要用到线性规划,不然很难解决
如果t2+w<s1的话说明无论如何不可能相遇
然后有四种情况,y=x+w, y=x-w可直接代入-w
#include<iostream>
#include<cstdio>
using namespace std;
double t1,s1,t2,s2,w;
double juge(double ww)
{
double s=(t2-t1)*(s2-s1);
if(t2+ww<s1)
return ;
if(t1+ww<=s1)
{
if(t2+ww<=s2)
return 0.5*(t2+ww-s1)*(t2+ww-s1); //
else
return 0.5*(t2+ww-s2+t2+ww-s1)*(s2-s1); //
}
if(t1+ww<s2)
{
if(t2+ww<=s2)
return 0.5*(t2-t1)*(t2+ww-s1+t1+ww-s1); //
else
return s-0.5*(s2-ww-t1)*(s2-ww-t1); //
}
else return s;
}
int main()
{
int t,k=;
cin>>t;
while(t--)
{
cin>>t1>>t2>>s1>>s2>>w;
double yinying=juge(w)-juge(-w);
yinying/=(t2-t1)*(s2-s1);
printf("Case #%d: %.8lf\n",k++,yinying);
}
}
UVA 11722 几何概型的更多相关文章
- 集训第六周 数学概念与方法 UVA 11722 几何概型
---恢复内容开始--- http://acm.hust.edu.cn/vjudge/problem/viewProblem.action?id=31471 题意,两辆火车,分别会在[t1,t2],[ ...
- Codeforces - 77B - Falling Anvils - 几何概型
https://codeforc.es/contest/77/problem/B 用求根公式得到: \(p-4q\geq0\) 换成熟悉的元: \(y-4x\geq0\) 其中: \(x:[-b,b] ...
- UVa 11971 - Polygon(几何概型 + 问题转换)
链接: https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem& ...
- UVa 11346 - Probability(几何概型)
链接: https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem& ...
- UVA 11346 Probability (几何概型, 积分)
题目链接:option=com_onlinejudge&Itemid=8&page=show_problem&problem=2321">https://uva ...
- 数学概念——A 几何概型
You are going from Dhaka to Chittagong by train and you came to know one of your old friends is goin ...
- 几何概型 uva11722
#include<bits/stdc++.h> using namespace std; int t1,t2,s1,s2,w; int get(int b) { ; int d=s2-s1 ...
- uva 11722 - Joining with Friend(概率)
题目连接:uva 11722 - Joining with Friend 题目大意:你和朋友乘火车,而且都会路过A市.给定两人可能到达A市的时段,火车会停w.问说两人能够见面的概率. 解题思路:y = ...
- UVa 11722 (概率 数形结合) Joining with Friend
高中也做个这种类似的题目,概率空间是[t1, t2] × [s1, s2]的矩形,设x.y分别代表两辆列车到达的时间,则两人相遇的条件就是|x - y| <= w 从图形上看就是矩形夹在两条平行 ...
随机推荐
- word 2010中如何创建多级目录和多级列表
原文地址:http://wenku.baidu.com/link?url=KkSmYTqogxA5VJkLCGb957E5fIGN5S50FUx7IpAWWWKWWRYvaeGl2IvX-dFP25r ...
- DNA Sequence - POJ 2778(AC自动机+矩阵乘法)
题目大意:DNA序列是有 ATGC 组成的,现在知道一些动物的遗传片段有害的,那么如果给出这些有害的片段,能否求出来所有长度为 N 的基因中有多少是不包含这些有害片段的. 分析:也是断断续续做了一 ...
- nginx 代理概念理解
学习nginx http://www.nginx.cn/nginx-how-to nginx官方定义: Nginx 是一个高性能的 Web 和反向代理服务器. 首先明确一个概念 反向代理 反向代理(R ...
- 杠杠做的全屏随鼠标滚动显示图片,类似于PPT效果
图片有22张,是一张张加载的,耐心点,鼠标一直尝试向下滚就行了. 图片来自<天空之境:乌尤尼盐沼>,一个好美好美的地方 引个流,欢迎去我的博客看看:http://blog.cxycs.co ...
- EntityFramework 使用Linq处理内连接(inner join)、外链接(left/right outer join)、多表查询
场景:在实际的项目中使用EntityFramework都会遇到使用Ef处理连接查询的问题,这里做一些小例子如何通过Linq语法处理内连接(inner join).外连接(left/right oute ...
- 使用easy_install安装numpy、pandas、matplotlib及各种第三方模块
倒腾了一晚上最终把题目中的环境配好了.以下简要说明.留作资料.并共享. 1.安装python. 在cmd中能进入python环境,通过把python路径加入到系统路径中就可以实现. 2.安装easy- ...
- jni那点事
今天说一下在jni开发中常另新手迷惑的JNIEnv这个东西 比如一个c语言的函数 JNIEXPORT jstring JNICALL Java_com_mmmmar_nativethread_Main ...
- jquery在ie浏览器下中文乱码的问题
用jquery的ajax方法在调用后台数据发现中文乱码,无法解析中文的url,而在别的浏览器下面就不会,如下所示 $.ajax({ type:'get', url:'薛之谦-演员.lrc', asyn ...
- Android 项目建立步骤
使用eclipse,进行安卓开发,在建立项目的时候,有些步骤必须注意的, 本文就是对使用eclipse进行android开发的简单说明: 一.模拟器配置设定 使用eclipse开发安卓,需要用到and ...
- codevs 1689 搭建高塔
/*机智sort二维转一维*/ #include<iostream> #include<cstdio> #include<cstring> #include< ...