11722 - 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

题解:题意就是两个人见面,到达时间都在一个时间段内,然后停留w分钟再走,让求见面的概率;

两个把两个人到达时间设为x,y则两个人见面为 -w=<x-y<=w;

在二维坐标系上画出来,总样本是(t2-t1)(s2-s1);只需要求平行线-w=<x-y<=w与矩形相交的面积比矩形的面积即可;

代码:

#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<algorithm>
using namespace std;
#define mem(x,y) memset(x,y,sizeof(x))
double t1,t2,s1,s2,w;
double getmj(double b){
double y1=t1+b,y2=t2+b,x1=s1-b,x2=s2-b;
if(y1>=s2)return 0;
if(x1>=t2)return (s2-s1)*(t2-t1);
/*if(y1>=s1&&y2>=s2)return 0.5*(s2-y1)*(t2-x2-t1);
if(y1<s1&&y2>=s2)return 0.5*(s2-s1)*(x2-x1)+(x1-t1)*(s2-s1);
if(y1>s1&&y2<s2)return 0.5*(t2-t1)*(y2-y1)+(t2-t1)*(s2-y2);
if(x1>=t2)return (s2-s1)*(t2-t1);
if(y1<=s1&&y2<=s2)return (s2-s1)*(t2-t1)-0.5*(t2-x1)*(y2-s1);*/
if(y1>=s1){
if(x2<=t2)return 0.5*(x2-t1)*(s2-y1);
else return 0.5*(t2-t1)*(y2-y1)+(s2-y2)*(t2-t1);
}
else{
if(x2<=t2)return 0.5*(s2-s1)*(x2-x1)+(x1-t1)*(s2-s1);
else return (s2-s1)*(t2-t1)-0.5*(t2-x1)*(y2-s1); //坑,这里写错了,错了半天,其实角度45度,写一个就行
}
}
int main(){
int T,kase=0;
scanf("%d",&T);
while(T--){
scanf("%lf%lf%lf%lf%lf",&t1,&t2,&s1,&s2,&w);
double ans=(getmj(-w)-getmj(w))/((s2-s1)*(t2-t1));
printf("Case #%d: %.8lf\n",++kase,ans);
}
return 0;
}

  

uva11722 - Joining with Friend(几何概率)的更多相关文章

  1. UVa 11722 Joining with Friend (几何概率 + 分类讨论)

    题意:某两个人 A,B 要在一个地点见面,然后 A 到地点的时间区间是 [t1, t2],B 到地点的时间区间是 [s1, s2],他们出现的在这两个区间的每个时刻概率是相同的,并且他们约定一个到了地 ...

  2. UVA - 11722 Joining with Friend 几何概率

                            Joining with Friend You are going from Dhaka to Chittagong by train and you ...

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

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

  4. UVA11722 Jonining with Friend

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

  5. Entity Framework: Joining in memory data with DbSet

    转载自:https://ilmatte.wordpress.com/2013/01/06/entity-framework-joining-in-memory-data-with-dbset/ The ...

  6. uva 11722 - Joining with Friend(概率)

    题目连接:uva 11722 - Joining with Friend 题目大意:你和朋友乘火车,而且都会路过A市.给定两人可能到达A市的时段,火车会停w.问说两人能够见面的概率. 解题思路:y = ...

  7. How to quickly become effective when joining a new company

    How to quickly become effective when joining a new company The other day my colleague Richard asked ...

  8. Apache Spark as a Compiler: Joining a Billion Rows per Second on a Laptop(中英双语)

    文章标题 Apache Spark as a Compiler: Joining a Billion Rows per Second on a Laptop Deep dive into the ne ...

  9. LINQ之路13:LINQ Operators之连接(Joining)

    Joining IEnumerable<TOuter>, IEnumerable<TInner>→IEnumerable<TResult> Operator 说明 ...

随机推荐

  1. spring 加载配置文件的相关配置总结

    PropertyPlaceholderConfigurer      注意: Spring容器仅允许最多定义一个PropertyPlaceholderConfigurer(或<context:p ...

  2. solr6环境搭建

    1.下载并安装jdk1.8,配置环境变量 2.下载并安装tomcat8(8以上) 3.下载solr源码,转变部署solr a)[solr-6.2.0\server\solr-webapp]下的weba ...

  3. JavaSE复习日记 : 条件判断语句

    /* 条件控制语句:if(){}else{} 语法: 第一种结构:有不执行的情况 if(boolean表达式){ //第一位真,就执行里面的语句,为假就不执行 java语句; } 第二种结构: if( ...

  4. Android应用开发基础篇(7)-----BroadcastReceiver

    链接地址:http://www.cnblogs.com/lknlfy/archive/2012/02/22/2363644.html 一.概述 BroadcastReceiver,意思就是广播信息接收 ...

  5. Win7下安装Apache+PHP+MySQL

    Win 7 下搭建 WAMP 环境本文安装方法适用于 Windows7 下的 Apache + MySQL + PHP(WAMP)安装,同时也适用于 Windows XP 系统下的安装和配置.一.安装 ...

  6. php知识(第2天)

    运算符 PHP中运算符一共分为9类: 赋值运算符, 算术运算符,比较运算符, 逻辑运算符, 错误抑制符, 三目运算符, 位运算符, 自操作运算符, 连接操作符 算术运算符 算术运算: 基本运算符: + ...

  7. sqlserver 在将 nvarchar 值 'XXX' 转换成数据类型 int 时失败

    最近做oracle和sqlserver数据库兼容,感觉sqlserver真心没oracle好用,存储过程竟然只能返回int类型,疯了 疯了 存储过程的output及return的区别 sql取整 ce ...

  8. 循环-10. 求序列前N项和(15)

    #include<iostream>#include<iomanip>using namespace std;int main(){    double i,n,t,a,b;  ...

  9. jQuery.ui autoComplete使用

    官网  http://api.jqueryui.com/autocomplete/#option-source 参考了 http://www.cnblogs.com/lwme/archive/2012 ...

  10. LED板上芯片(COB)封装流程

    LED 板上芯片(Chip On Board,COB)封装流程是,首先在基底表面用导热环氧树脂(一般用掺银颗粒的环氧树脂)覆盖硅片安放点, 然后将硅片 间接安放正在基底表面,热处理至硅片牢固地固定正在 ...