链接:http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&category=&problem=2769&mosmsg=Submission+received+with+ID+13959080

Problem J: 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

Output for Sample Input

2

1000 1040 1000 1040 20

720 750 730 760 16

Case #1: 0.75000000

Case #2: 0.67111111

Problem Setter: Md. Towhidul Islam Talukder

Special Thanks: Samee Zahur, Mahbubul Hasan

简单二维线性规划问题:

输入:5 integers t1, t2, s1, s2, w (360 ≤ t1 < t2 < 1080, 360 ≤ s1 < s2 < 1080 and 1 ≤ w ≤ 90).

目标函数:0<=|s-t|<=w;计算目标的补集更简单

步骤:画出坐标轴,注意分类讨论;

分类讨论:(图形见书P141)

确定4个交点:

A(t1,t1+w),B(s2-w,s2),C(t2,t2-w),D(s1+w,s1)

aim1=0.5*(s2-ay)*(bx-t1),ay>=s1 && bx<=t2;

aim1=0.5*((s2-ay)+(s2-(t2+w))*(t2-t1), ay>=s1 && bx>t2;

aim1=0.5*(s1-w-t1+(bx-t1))*(s2-s1),ay<s1 && bx<=t2;

aim1=0;//否则

aim2=0.5*(s2-ay)*(bx-t1),cy<=s2 && dx>=t1;

aim2=0.5*((t1-w-s1)+(cy-s1))*(t2-t1), cy<=s2 && dx<t1;

aim2=0.5*(t2-(s2+w)+(t2-dx))*(s2-s1),cy>s2 && dx<=t1;

aim2=0;//否则

aim=((s2-s1)*(t2-t1)-aim1-aim2)/(s2-s1)*(t2-t1);

*/

#include <iostream>
#include <cmath>
#include <algorithm>
#include <cstring>
#include<cstdio>
using namespace std;
double t1,t2,s1,s2,w;
double area(double b) // 求y=x+b下方在矩形中截取的面积
{
double s=(t2-t1)*(s2-s1);
double x1=t1,y1=t1+b;
double x2=t2,y2=t2+b;
if(y2<=s1) // 直线交于矩形右下顶点或者以下
return 0;
if(y1<=s1) // 直线交于矩形下面边
{
if(y2<=s2) // 直线交于矩形右面边
return 0.5*(y2-s1)*(t2-(s1-b));
else // 直线交于矩形上面边
return 0.5*(t2-s1+b+t2-s2+b)*(s2-s1);
}
else if(y1<s2) // 直线交于矩形左面边
{
if(y2<=s2) //直线交于矩形右面边
return 0.5*(t1+b-s1+t2+b-s1)*(t2-t1);
else // 直线交于矩形上面边
return s-0.5*(s2-t1-b)*(s2-t1-b);
}
else
return s;
}
int main()
{
int t;
scanf("%d",&t);
for(int cas=1;cas<=t;cas++)
{
scanf("%lf%lf%lf%lf%lf",&t1,&t2,&s1,&s2,&w);
double ans=area(w)-area(-w);
ans/=(s2-s1)*(t2-t1);
printf("Case #%d: %.8lf\n",cas,ans);
}
return 0;
}

UVA11722概率问题之线性规划的更多相关文章

  1. 竞价拍卖理论的介绍(RTB模型中使用第二竞价模型,为的是纳什平衡,保护所有多方利益)

    英式拍卖 是最普通的拍卖方式,其形式是拍卖过程中,竞价按阶梯,从低到高,依次递增.最终由出价最高者获得拍卖物品(竞买人变成买受人). The first price auction: a form o ...

  2. UVA11722(见面概率)

    题意:       有一个车站,两个人想要在这个车站见面,第一个人会在t1到t2之间的任意一个时刻到(时间上任意一点概率一样),并且停留w时间,第二个人是s2到s2的时间段到,停留也是w,问两个人的见 ...

  3. UVA11722 Jonining with Friend

    Joining with Friend You are going from Dhaka to Chittagong by train and you came to know one of your ...

  4. [bzoj2152][聪聪和可可] (点分治+概率)

    Description 聪聪和可可是兄弟俩,他们俩经常为了一些琐事打起来,例如家中只剩下最后一根冰棍而两人都想吃.两个人都想玩儿电脑(可是他们家只有一台电脑)……遇到这种问题,一般情况下石头剪刀布就好 ...

  5. sqlserver中根据表中的配置概率取到数据

      create proc pr_zhanglei_test1 /*功能描述: 根据t_zhanglei_test1中perc设置的概率,取到相应数据old_id */ as declare @per ...

  6. 【BZOJ-3143】游走 高斯消元 + 概率期望

    3143: [Hnoi2013]游走 Time Limit: 10 Sec  Memory Limit: 128 MBSubmit: 2264  Solved: 987[Submit][Status] ...

  7. 【BZOJ-3270】博物馆 高斯消元 + 概率期望

    3270: 博物馆 Time Limit: 30 Sec  Memory Limit: 128 MBSubmit: 292  Solved: 158[Submit][Status][Discuss] ...

  8. UVA1637Double Patience(概率 + 记忆化搜索)

    训练指南P327 题意:36张牌分成9堆, 每堆4张牌.每次拿走某两堆顶部的牌,但需要点数相同.如果出现多种拿法则等概率的随机拿. 如果最后拿完所有的牌则游戏成功,求成功的概率. 开个9维数组表示每一 ...

  9. caffe机器学习自带图片分类器classify.py实现输出预测结果的概率及caffe的web_demo例子运行实例

    caffe机器学习环境搭建及python接口编译参见我的上一篇博客:机器学习caffe环境搭建--redhat7.1和caffe的python接口编译 1.运行caffe图片分类器python接口 还 ...

随机推荐

  1. Android View加载圆形图片且同时绘制圆形图片的外部边缘边线及边框:LayerDrawable实现

     Android View加载圆形图片且同时绘制圆形图片的外部边缘边线及边框:LayerDrawable实现 LayerDrawable实现的结果和附录文章1,2,3中的layer-list一致. ...

  2. BZOJ 3721: PA2014 Final Bazarek【乱搞】

    有n件商品,选出其中的k个,要求它们的总价为奇数,求最大可能的总价. Input 第一行一个整数n(1<=n<=1000000),表示商品数量.接下来一行有n个整数,表示每件商品的价格,范 ...

  3. 【尺取】HDU Problem Killer

    acm.hdu.edu.cn/showproblem.php?pid=5328 [题意] 给定一个长度为n的正整数序列,选出一个连续子序列,这个子序列是等差数列或者等比数列,问这样的连续子序列最长是多 ...

  4. k/3cloud表格控件块粘贴代码逻辑

    大家可以在表单插件EntityBlockPasting事件中自己处理,然后将cancel设置为true.以下代码可以参考一下,插件代码中需要将其中一些属性或方法修改,例如this.BusinessIn ...

  5. D. Little Artem and Dance---cf669D

    http://codeforces.com/problemset/problem/669/D 题目大意: 有n对人 男生和女生 开始时  每个人的标号是(1,2,3,...n) 女生们围成一个圈  男 ...

  6. java实验(三)——课堂小测

    这次的课堂小测是用以前生成的那些四则运算的代码,然后将这些题目写到一个文件中,再通过这个文件读取题目的信息,每读入一个答案的时候,遇到星号的时候,等待用户输入然后判断输入的答案是否正确,然后输出小一道 ...

  7. 【python】super()

    转自: http://www.cnblogs.com/lovemo1314/archive/2011/05/03/2035005.html

  8. curl 中文乱码

    curl 中文乱码 学习了:https://blog.csdn.net/thc1987/article/details/52583789 学习了: http://blog.itpub.net/2903 ...

  9. CentOS LAMP一键安装网站环境及添加域名

    一般的VPS用户普遍使用一键安装包和WEB管理面板居多,在一键安装包中,使用LAMP和LNMP的普遍居多. 第一个版本的LAMP环境包安装过程以及建站过程分享出来. 第一.LAMP一键包环境的安装 目 ...

  10. Bound mismatch: The typae CertificateDirectory is not a valid substitute for the bounded parameter <M extends Serializable>

    这是因为架包没导对或者关联的项目不是在同一个工作空间.