链接: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. [转]制作一个64M的U盘启动盘(mini linux + winpe +dos toolbox)

    自己动手定制winpe+各类dos工具箱U盘启动盘+minilinux 由于一个64M老U盘,没什么用,拿来发挥余热.如果U盘够大,可以使用功能更强大的mini linux和带更多工具的winpe.这 ...

  2. 从jmm模型漫谈到happens-befor原则

    首先,代码都没有用ide敲,所以不要在意格式,能看懂就行jmm内存模型: jmm是什么? jmm说白了就是定义了jvm中线程和主内存之间的抽象关系的一种模型,也就是线程之间的共享变量存储在主内存,而每 ...

  3. 【Educational Codeforces Round 48】

    A:https://www.cnblogs.com/myx12345/p/9843001.html B:https://www.cnblogs.com/myx12345/p/9843021.html ...

  4. Codeforces947D. Picking Strings

    $n \leq 100000,m \leq 100000$,给长度$n$的字符串$s$和$m$的字符串$t$,只含ABC.定义串$a$可以经过任意次如下操作变成其他串. 现在$q \leq 10000 ...

  5. SQL SERVER 2012 第五章 创建和修改数据表 の SQL SERVER中的对象名

    [ServerName.[DataBaseName.[SchemeName.]]]ObjectName 服务器名,数据库名,模式名,对象名 其中模式是一个新出的坑爹的东西.

  6. Python学习之-- IO 操作

    阻塞IO / 非阻塞IO /IO多路复用 / 异步IO 说明:同步IO包含(阻塞IO / 非阻塞IO /IO多路复用),因为他们有个共同特性就是都需要内核态到用户态的一个等待. 基本概念解释,环境限定 ...

  7. loj6158 A+B Problem (扩展KMP)

    题目: https://loj.ac/problem/6158 分析: 先把S串逆置,就是从低位向高位看 我们再弄个T串,S串前面有x个连续的0,那么T串前面也有x个连续的0 第x+1位,满足S[x+ ...

  8. sublime text 3(Build 3103)最新注冊码

    原来注冊过的sublime text 3近期更新了.没想到原来的注冊码就失效了,只是我找到了最新的注冊码(Build 3103),与大家分享一下(第一个亲測可用). -– BEGIN LICENSE ...

  9. volatile关键字解析&内存模型&并发编程中三概念

    原文链接: http://www.cnblogs.com/dolphin0520/p/3920373.html volatile这个关键字可能很多朋友都听说过,或许也都用过.在Java5之前,它是一个 ...

  10. 转: eclipse 快捷键列表(功能清晰版本)

    转自: http://www.uml.org.cn/mobiledev/201110092.asp Eclipse 在开发中使用到的快捷键很实用噢 Ctrl+1 快速修复(最经典的快捷键,就不用多说了 ...