题目链接

题意:

  两个人坐火车, 在某个城市到站的时间段分别为[t1, t2] , [s1, s2],停在站台的时间均为w。

  问, 若两人能见面的概率。

思路:

  一道基础的几何概型, p = s(m)/s(n)。

  令x1 = t1, x2 = t2。

  令y1 = s1, y2 = s2。

  这样这四条直线就围成一个矩形,若两人见面, 则应该满足在 y = x ± w 这两条直线之间。

  即本题求解, y = x ± w 在矩形中所围面积 与矩形面积之比。

  根据 y = x + b 这条线与矩形的交点不同, 把矩形分成四个区域, 计算面积这里规定以左上角的点为参考点计算。

  阴影面积即为所求

  1)

  

  2)

  这种情况将之补成一个三角形, 用大三角形减去小三角形的面积即可。

  3)

  这种情况, 用矩形面积减去小三角形面积即可。

  4)

  这种情况也用补全三角形来求解

  other)

  如果直线相交于左上角, 那么面积为0. 如果在右下角, 那么面积为矩形面积。

  

代码如下:

 #include <cmath>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <ctime>
#include <climits>
#include <set>
#include <map>
#include <list>
#include <queue>
#include <string>
#include <vector>
#include <fstream>
#include <iterator>
#include <iostream>
#include <algorithm>
using namespace std;
#define LL long long
#define MAXN 4
#define MOD 1000000007
#define eps 1e-6
double s[MAXN], t[MAXN], w;
double weight, high;
double get_area(double b)
{
double tx = t[] - b;
double dx = t[] - b;
double ly = s[] + b;
double ry = s[] + b;
//printf("tx: %.7lf, dx: %.7lf, ly: %.7lf, ry: %.7lf\n", tx, dx, ly, ry);
bool OnTop = (tx <= s[] && tx >= s[]);
bool OnDown = (dx <= s[] && dx >= s[]);
bool OnLeft = (ly <= t[] && ly >= t[]);
bool OnRight = (ry <= t[] && ry >= t[]); if(OnTop && OnLeft)
return 0.5 * (tx - s[]) * (t[] - ly);
if(OnLeft && OnRight)
return 0.5 * ((t[] - ly) * (tx - s[]) - (t[] - ry) * (tx - s[]));
if(OnDown && OnTop)
return 0.5 * ((tx - s[]) * (t[] - ly) - (dx - s[]) * (t[] - ly));
if(OnDown && OnRight)
return weight * high - 0.5 * (s[] - dx) * (ry - t[]);
return ly >= t[] ? : weight * high;
} int main()
{
int T;
int kcase = ;
scanf("%d", &T);
while(T --)
{
scanf("%lf %lf %lf %lf %lf", &t[], &t[], &s[], &s[], &w);
high = t[] - t[];
weight = s[] - s[];
double area_top = get_area(w);
double area_down = get_area(- * w);
double ans = high * weight;
//printf("%.8lf %.8lf %.8lf\n", area_top, area_down, ans);
ans = (area_down - area_top) / ans;
printf("Case #%d: %.8lf\n", ++ kcase, ans);
}
return ;
}

Uva_11722 Joining with Friend的更多相关文章

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

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

  2. Entity Framework: Joining in memory data with DbSet

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

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

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

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

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

  5. 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 ...

  6. 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 ...

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

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

  8. SQL 基础学习(2) Joining 和function , 作业没有做,需要看百宝箱。NOsql的概念

    SQL 基础学习(2) Joining 可以同时关联(joining)多张表进行复杂的查询. 相比于用Rails捞出数据再用Ruby进行过滤组合,使用SQL更加高效,节能. 以下是 users has ...

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

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

随机推荐

  1. c#常用工具类:文件和二进制转换

    //================二进制相关转换类============== #region 将文件转换为二进制数组 /// <summary> /// 将文件转换为二进制数组 /// ...

  2. W5500问题集锦(持续更新中)

    在"WIZnet杯"以太网技术竞赛中,有非常多參赛者在使用中对W5500有各种各样的疑问,对于这款WIZnet新推出的以太网芯片,使用中大家是不是也一样存在下面问题呢?来看一看: ...

  3. [rxjs] Throttled Buffering in RxJS (debounce)

    Capturing every event can get chatty. Batching events with a throttled buffer in RxJS lets you captu ...

  4. iOS AFNetWorking源码详解(一)

    来源:Yuzeyang 链接:http://zeeyang.com/2016/02/21/AFNetWorking-one/ 首先来介绍下AFNetWorking,官方介绍如下: AFNetworki ...

  5. oracle常用数据类型

    oracle中常用数据类型分为三大类:

  6. vi 使用笔记

    基本A 当前行追加J 去除本行和下一行之间的换行符(写CSS利器)~ 光标所在处的字符进行大小写互换* 向前搜索目前光标所在的单词# 向后搜索目前光标所在的单词% 查找与光标所在处相匹配的反括号, 包 ...

  7. 字符串右移n位(C++实现)

    字符串右移n位(C++实现): // ShiftNString.cpp : 定义控制台应用程序的入口点. // #include "stdafx.h" #include <i ...

  8. [转载]SharePoint 网站管理-PowerShell

    1. 显示场中所有可用的网站集 Get-SPSite Get-SPSite 2. 显示某一Web应用程序下可用的网站集 Get-SPSite –WebApplication "SharePo ...

  9. WinEdt打开UTF-8文件乱码问题——ctex[转]

    原来这么简单,mark一下! [转自:http://fstang.diandian.com/post/2012-04-17/40030401020] 其实这个问题网上文章已经有一大堆了...我只是记录 ...

  10. Linux同步时间命令ntpdate

    转自:http://orgcent.com/linux-ntpdate/ 由于要同步Linux服务器的时间,为了保证时间的高度准确性,放弃date命令而转向ntpdate(同步时间命令). 方案如下: ...