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 2 1000 1040 1000 1040 20 720 750 730 760 16 Sample Output Case #1: 0.75000000 Case #2: 0.67111111

比较显然的线性规划,几何概型,之前一道类似的题出到了我们数学卷子上,被我秒了。。。

主要是求面积,分好情况

 #include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <algorithm>
#include <queue>
#include <vector>
#include <cmath>
#define min(a, b) ((a) < (b) ? (a) : (b))
#define max(a, b) ((a) > (b) ? (a) : (b))
#define abs(a) ((a) < 0 ? (-1 * (a)) : (a))
inline void swap(int &a, int &b)
{
long long tmp = a;a = b;b = tmp;
}
inline void read(int &x)
{
x = ;char ch = getchar(), c = ch;
while(ch < '' || ch > '') c = ch, ch = getchar();
while(ch <= '' && ch >= '') x = x * + ch - '', ch = getchar();
if(c == '-') x = -x;
} const int INF = 0x3f3f3f3f; int t1,t2,s1,s2,t,ca,w; double calc(int w)
{
if(t1 + w >= s2) return (s2 - s1) * (t2 - t1);
if(t2 + w <= s1) return ;
if(t1 + w >= s1)//left
{
if(s2 - w >= t2) return (double)(t1 + w - s1 + t2 + w - s1) * (t2 - t1) * 0.5; //right
else return (s2 - s1) * (t2 - t1) - (double)(s2 - t1 - w) * (s2 - w - t1) * 0.5; //up
}
else
{
if(s2 - w >= t2) return (double)(t2 + w - s1) * (t2 - s1 + w) * 0.5; //right
else return (double)(t2 - s2 + w + t2 - s1 + w) * (s2 - s1) * 0.5;//up
}
return ;
} int main()
{
read(t);
for(;t;--t)
{
++ ca;
read(t1), read(t2), read(s1), read(s2), read(w);
printf("Case #%d: %.8lf\n", ca, (calc(w) - calc(-w)) / ((s2 - s1) * (t2 - t1)));
}
return ;
}

UVA11722

UVA11722 Jonining with Friend的更多相关文章

  1. [uva11722&&cogs1488]和朋友会面Joining with Friend

    几何概型,<训练指南>的题.分类讨论太神啦我不会,我只会萌萌哒的simpson强上~这里用正方形在y=x-w的左上方的面积减去在y=x+w左上方的面积就是两条直线之间的面积,然后切出来的每 ...

  2. uva11722 - Joining with Friend(几何概率)

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

  3. 几何概型 uva11722

    #include<bits/stdc++.h> using namespace std; int t1,t2,s1,s2,w; int get(int b) { ; int d=s2-s1 ...

  4. UVA11722概率问题之线性规划

    链接:http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&am ...

  5. UVA11722(见面概率)

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

  6. JSZX_HC_2016_R5

    #1 ccz 200 #2 CTL 130 #3 KPM 130 本来以为准备挺充分的,开始后还是出现一些状况 >_< 好在还算顺利…… A AC人数:4   平均分:70 题目描述 给定 ...

  7. uva 11722 Joining with Friend

    https://vjudge.net/problem/UVA-11722 题意:你和朋友都要乘坐火车,并且都会途径A城市.你们很想会面,但是你们到达这个城市的准确时刻都无法确定.你会在时间区间[t1, ...

随机推荐

  1. Berlin Programming Contest 2004 Heavy Transportation /// dijkstra oj22604

    题目大意: 输入t:t为样例数 每个样例输入n,m:n 为顶点个数 m 为路径数 接下来m行  每行输入 u v w :从 u 点到 v 点的路承重为 w 输出 车子若想通过 1~n的最短路 车重需限 ...

  2. 线性回归代码实现(matlab)

    1 代价函数实现(cost function) function J = computeCost(X, y, theta) %COMPUTECOST Compute cost for linear r ...

  3. array_map、array_walk、array_filter三个函数的区别

    array_walk --- 使自定的函数能处理数组的每个元素 bool array_walk ( array &array, callback funcname [, mixed userd ...

  4. 代码内存泄露检测工具(linux gcc + valrind)

    参考博客: https://www.cnblogs.com/wangkangluo1/archive/2011/07/20/2111248.html linux命令如下:valgrind --tool ...

  5. 「题解」:[BZOJ4358]permu

    问题: permu 时间限制: 30 Sec  内存限制: 512 MB 题面 题目描述 给出一个长度为n的排列P(P1,P2,...Pn),以及m个询问.每次询问某个区间[l,r]中,最长的值域 连 ...

  6. sql.xml 循环插入与修改写法

    // 插入 (交互一次数据库) <insert id="insertClient"> insert into m_linknodeclient (LinkClientI ...

  7. JavaScript中数组的集合和映射

    集合 集合(set)是在ES6中引入的一种数据结构,用于表示唯一值的集合,所以它不能包含重复值.接 下来这一小节,就让我们具体来看一下这种新的数据结构. Set集合是一种无重复元素的列表,这是这种数据 ...

  8. Template-Thymeleaf:Thymeleaf

    ylbtech-Template-Thymeleaf:Thymeleaf 1.返回顶部   2.返回顶部   3.返回顶部   4.返回顶部   5.返回顶部 0. https://www.thyme ...

  9. Python学习day11-函数基础(1)

    figure:last-child { margin-bottom: 0.5rem; } #write ol, #write ul { position: relative; } img { max- ...

  10. jsp 页面跳转后修改数据,返回时不更新

    项目jsp页面上用隐藏input框接收获取数据,在跳转入另一页面前,js操作修改数据,但返回时发现无效. 需求是点击抽奖后机会减少一次,但是当做跳转操作后返回时,次数有缓存问题 jsp: <in ...