UVA11722 Jonining with Friend
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的更多相关文章
- [uva11722&&cogs1488]和朋友会面Joining with Friend
几何概型,<训练指南>的题.分类讨论太神啦我不会,我只会萌萌哒的simpson强上~这里用正方形在y=x-w的左上方的面积减去在y=x+w左上方的面积就是两条直线之间的面积,然后切出来的每 ...
- uva11722 - Joining with Friend(几何概率)
11722 - Joining with Friend You are going from Dhaka to Chittagong by train and you came to know one ...
- 几何概型 uva11722
#include<bits/stdc++.h> using namespace std; int t1,t2,s1,s2,w; int get(int b) { ; int d=s2-s1 ...
- UVA11722概率问题之线性规划
链接:http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&am ...
- UVA11722(见面概率)
题意: 有一个车站,两个人想要在这个车站见面,第一个人会在t1到t2之间的任意一个时刻到(时间上任意一点概率一样),并且停留w时间,第二个人是s2到s2的时间段到,停留也是w,问两个人的见 ...
- JSZX_HC_2016_R5
#1 ccz 200 #2 CTL 130 #3 KPM 130 本来以为准备挺充分的,开始后还是出现一些状况 >_< 好在还算顺利…… A AC人数:4 平均分:70 题目描述 给定 ...
- uva 11722 Joining with Friend
https://vjudge.net/problem/UVA-11722 题意:你和朋友都要乘坐火车,并且都会途径A城市.你们很想会面,但是你们到达这个城市的准确时刻都无法确定.你会在时间区间[t1, ...
随机推荐
- uoj279 题目交流通道
题目:告诉你每两个点之间的最短路距离.构造每条边边权<=m的无向完全图.求有多少种不同边权的图满足最短路限制?n<=400. 标程: #include<cstdio> #inc ...
- thinkphp 模板赋值
如果要在模板中输出变量,必须在在控制器中把变量传递给模板,系统提供了assign方法对模板变量赋值,无论何种变量类型都统一使用assign赋值. 大理石平台检定规程 $this->assign( ...
- swiper 插件里面嵌套可滚动内容
在移动端使用swiper的整屏滚动,如果slide里面有滚动内容的话,滚动的时候会整个页面一起滚动,如果想里面的滚动区域单独滚动的话,可以在初始化swiper的时候添加上 noSwipingClass ...
- 老师的blog整理 .网络编程部分 .网络编程部分 前端部分 django基础部分
老师的blog整理 .网络编程部分 .网络编程部分 前端部分 django基础部分 老师的blog整理 python基础部分: 宝哥blog: https://www.cnblogs.com/gu ...
- spring boot 中 rabbit mq基础例子
1.先安装ELANG,再按照RabbitMQ 2.打开RabbitMQ控制台:rabbit command prompt 1.设置elang的路径:set ERLANG_HOME=D:\work_pr ...
- 01_springmvc基础入门
一.springmvc概述 Spring MVC是基于Model2实现的技术框架,在Spring MVC中,Action被称为Controller(控制器).Spring的Web框架围绕Dispatc ...
- 安装office2019
win10系统安装office2019 安装文件下载 https://pan.baidu.com/s/1VnqJ-hNwysPKBhdzE3FSww#list/path=%2F&parentP ...
- AppScan的基础使用
AppScan是用于Web项目的安全测试工具,扫描网站所有url,自动测试是否存在各种类型的漏洞.AppScan安装在Windows环境上,版本越高,规则库越安全,扫描越全面. 1. 打开AppS ...
- .NET Framework的属性类对控件的支持功能
ToolBoxItem 此属性为类特性.属于工具箱属性,可以设置当前控件是否在工具箱中显示,以及所在工具箱项的类型名称等信息.默认生成的控件都显示在工具箱中. 更多设计时属性介绍: 4.3 属性的 ...
- visio去除直线交叉处的歪曲
1 问题描述 Visio画图时,两根直线交叉时,总是默认会出现一个跨线的标志,如下图所示: 2 解决办法 在2007前的版本,可以通过以下方式解决: 选中线条,然后菜单的格式->行为->连 ...