链接: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. ZOJ3860-Find the Spy

    Find the Spy Time Limit: 2 Seconds      Memory Limit: 65536 KB Whoooa! There is a spy in Marjar Univ ...

  2. Codeforces 892 A.Greed

    A. Greed time limit per test 2 seconds memory limit per test 256 megabytes input standard input outp ...

  3. 兴奋剂检查(vijos 1426)

    背景 北京奥运会开幕了,这是中国人的骄傲和自豪,中国健儿在运动场上已经创造了一个又一个辉煌,super pig也不例外……………… 描述 虽然兴奋剂是奥运会及其他重要比赛的禁药,是禁止服用的.但是运动 ...

  4. CodeForces - 743B Chloe and the sequence

    暴力肯定是无法做的 当时做的时候 当成一道递推来做的 用到分治的思想 想象一串长度为2n+1的列 那么前n个为前一串数 后n个是前一串数的reverse 第n+1个数 为第几串的编号 例如 第几串 中 ...

  5. 栈 练习 Codevs 3137 3138 3139

    3137 栈练习1 时间限制: 1 s  空间限制: 128000 KB  题目等级 : 黄金 Gold 题目描述 Description 给定一个栈(初始为空,元素类型为整数,且小于等于100),只 ...

  6. Treasure Hunt--poj1066(最短路加判断线段的关系)

    http://poj.org/problem?id=1066 题目大意:有n条线段 他们都在这个房间里   最后有一个点代表起始位置 现在想通过墙出去  他只能爆破每个房间的中点的门   问最少的门通 ...

  7. 从ASP.NET Core 3.0 preview 特性,了解CLR的Garbage Collection

    前言 在阅读这篇文章:Announcing Net Core 3 Preview3的时候,我看到了这样一个特性: Docker and cgroup memory Limits We conclude ...

  8. Enhance Magento 404 page

    Magento default installation already has a predefined custom 404 page (no-route). But is it enough t ...

  9. HTC 328T 提示手机存储不足 out of space怎么办

    不要再用什么软件做优化,做清理,都是治标不治本啊. 1 用豌豆荚备份数据   2 手机恢复出厂设置   3 用豌豆荚恢复数据

  10. Ubuntu使用adb连接android手机失败unknown的解决的方法

    Ubuntu使用adb连接android手机失败unknown的解决的方法   Ubuntu下通过USB数据线连接G11手机后,adb可能无法识别到设备.依照一下步骤能够解决此问题. 1.在termi ...