第六周A题 - 几何概型

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

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

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

  2. Codeforces - 77B - Falling Anvils - 几何概型

    https://codeforc.es/contest/77/problem/B 用求根公式得到: \(p-4q\geq0\) 换成熟悉的元: \(y-4x\geq0\) 其中: \(x:[-b,b] ...

  3. UVa 11971 - Polygon(几何概型 + 问题转换)

    链接: https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem& ...

  4. UVa 11346 - Probability(几何概型)

    链接: https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem& ...

  5. UVA 11346 Probability (几何概型, 积分)

    题目链接:option=com_onlinejudge&Itemid=8&page=show_problem&problem=2321">https://uva ...

  6. 数学概念——A 几何概型

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

  7. 几何概型 uva11722

    #include<bits/stdc++.h> using namespace std; int t1,t2,s1,s2,w; int get(int b) { ; int d=s2-s1 ...

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

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

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

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

随机推荐

  1. 吐槽iOS国际化:关于NSLocalizedString的使用

    http://blog.csdn.net/aries4ever/article/details/8185405

  2. (组合数学3.1.1.2)UVA 10098 Generating Fast(使用字典序思想产生所有序列)

    /* * UVA_10098.cpp * * Created on: 2013年10月8日 * Author: Administrator */ #include <iostream> # ...

  3. java MessageFormat 应用 和 疑惑

    先来个demo String string = "{0}\"{1}\""; System.out.println(MessageFormat.format(st ...

  4. setTimeout的作用以及setTimeout延时0毫秒的作用

    以下代码输出的顺序是? console.log(1); setTimeout(function(){ console.log(2); }, 0); setTimeout(function(){ con ...

  5. 开源实时视频码流分析软件:VideoEye

    本文介绍一个自己做的码流分析软件:VideoEye.为什么要起这个名字呢?感觉这个软件的主要功能就是对"视频"进行"分析".而分析是要用眼睛来看的,因此取了&q ...

  6. PHP ORM框架与简单代码实现(转)

    对象关系映射(Object Relational Mapping,简称ORM)是一种为了解决面向对象与关系数据库存在的互不匹配的现象的技术. 简单的说,ORM是通过使用描述对象和数据库之间映射的元数据 ...

  7. Day2 - Python基础2 列表、字典、集合

    Python之路,Day2 - Python基础2   本节内容 列表.元组操作 字符串操作 字典操作 集合操作 文件操作 字符编码与转码 1. 列表.元组操作 列表是我们最以后最常用的数据类型之一, ...

  8. Core Python Notes

    开发需要在读 Python 核心编程,一些 Point 记录如下. ******************************************** 版本相关 标准版的 Python 是用 C ...

  9. 在ASP.NET将程序中将上传的附件存储到另一台文件服务器上的实现

    假定有两台服务器:A和B,其中A为Web服务器(IP:192.123.1.1, 为iis发布程序的服务器 ),B为文件服务器(IP: 192.123.2.2) 在文件服务器B中某个磁盘下创建一个共享文 ...

  10. 10、SQL Server 内置函数、临时对象、流程控制

    SQL Server 内置函数 日期时间函数 --返回当前系统日期时间 select getdate() as [datetime],sysdatetime() as [datetime2] getd ...