第六周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. 【索引】用PS3手柄在安卓设备上玩游戏系列

    谈安卓游戏对手柄的支持:http://www.cnblogs.com/duxiuxing/p/3729802.html 连接手柄和设备:http://www.cnblogs.com/duxiuxing ...

  2. 《Mathematical Olympiad——组合数学》——抽屉原理

    抽屉原理可以说是组合数学中最简单易懂的一个原理了,其最简单最原始的一个表达形式:对于n本书放到n-1个抽屉中,保证每个抽屉都要有书,则必存在一个抽屉中有2本书.但是这个简单的原理在很多问题中都能够巧妙 ...

  3. Java GC CMS 日志分析

    https://blogs.oracle.com/poonam/entry/understanding_cms_gc_logs 笔者对其中某几条记录又进行了详细说明,以下是一条完整的CMS日志记录的示 ...

  4. idea mac 快键键

    alt + 花 + 左右          上一步下一步 shift + 花 + F             全文检索 花 + O                       类查找 alt + 花 ...

  5. OPENCV第一篇

    了解过之前老版本OpenCV的童鞋们都应该清楚,对于OpenCV1.0时代的基于 C 语言接口而建的图像存储格式IplImage*,如果在退出前忘记release掉的话,就会照成内存泄露.而且用起来超 ...

  6. 南阳理工ACM-OJ 分数加减法 最大公约数的使用

    http://acm.nyist.net/JudgeOnline/problem.php?pid=111 简单模拟: #include <iostream> #include <st ...

  7. jQuery Ajax 实例 具体介绍$.ajax、$.post、$.get的使用

    Jquery在异步提交方面封装的非常好.直接用AJAX非常麻烦须要处理浏览器之间的兼容问题,Jquery大大简化了我们的这些操作操作.不用在考虑浏览器这方面的问题,能够直接使用! $.post.$.g ...

  8. Android 图片选择器

    图片选择器,遍历系统所有图片并显示,点击查看大图,长按选中,并将结果返回 字体颜色res/color建立text_selecor.xml <selector xmlns:android=&quo ...

  9. C++ XML 解释库

    rapidxml  http://rapidxml.sourceforge.net/index.htm

  10. Bridge 桥梁模式 桥接模式

    简介 将[抽象部分](Abstraction,人)与[实现部分](Implementor,人穿的衣服)分离,使它们都可以独立的变化. [业务抽象角色]引用[业务实现角色],或者说[业务抽象角色]的部分 ...