链接: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. oracle如何向空表中添加一个类型为clob的非空列

    一般的添加非空列的步骤是:先add可以为空的列,然后update该列为一个值(比如0),最后modify该列的类型 但是遇到类型为clob的就不行了.在modify这步时报错:ORA-22296:in ...

  2. [luoguP1866]滑动窗口(单调队列)

    传送门 可以搞2个单调队列. 然后,然后就没有然后了. # include <iostream> # include <cstdio> # include <cstrin ...

  3. PMU 简介

    目录 1:PMIC2:Battery管理3:功耗4:常见问题5:参考文献 PMIC[MT6322]    Source code structure Build option Battery char ...

  4. [NOIP1999] 提高组 洛谷P1016 旅行家的预算

    题目描述 一个旅行家想驾驶汽车以最少的费用从一个城市到另一个城市(假设出发时油箱是空的).给定两个城市之间的距离D1.汽车油箱的容量C(以升为单位).每升汽油能行驶的距离D2.出发点每升汽油价格P和沿 ...

  5. ubuntu 配置 samba, win7 map network device from linux

    一. samba的安装: # sudo apt-get insall samba # sudo apt-get install smbfs 二. 创建共享目录,或是找已经存在的文件夹,只要权限放开就行 ...

  6. POJ 1704 Georgia and Bob【博弈】

    题目链接: http://poj.org/problem?id=1704 题意: 给定棋子及其在格子上的坐标,两个人轮流选择一个棋子向左移动,每次至少移动一格,但是不可以碰到其他棋子.无路可走的时候视 ...

  7. js删除数组对象中符合条件的数据

    var data = [{}, {}, {}, {Id:1}] var datawilldele = [];//2,4,5 data.forEach(function (v, i,arry) { if ...

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

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

  9. MongoDB学习day09--Mongoose数据校验

    一.Mongoose检验参数 required : 表示这个数据必须传入max: 用于 Number 类型数据, 最大值 min: 用于 Number 类型数据, 最小值 enum:枚举类型, 要求数 ...

  10. css实现文字渐变

    css文件渐变虽然兼容性比较差,但是用在移动端和chrome中还是没有问题的. 实现文件渐变的方法有两种 1. 使用 background 的属性 2. 使用 mask 属性 方式一. <!DO ...