Uva_11722 Joining with Friend
题意:
两个人坐火车, 在某个城市到站的时间段分别为[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的更多相关文章
- [uva11722&&cogs1488]和朋友会面Joining with Friend
几何概型,<训练指南>的题.分类讨论太神啦我不会,我只会萌萌哒的simpson强上~这里用正方形在y=x-w的左上方的面积减去在y=x+w左上方的面积就是两条直线之间的面积,然后切出来的每 ...
- Entity Framework: Joining in memory data with DbSet
转载自:https://ilmatte.wordpress.com/2013/01/06/entity-framework-joining-in-memory-data-with-dbset/ The ...
- uva11722 - Joining with Friend(几何概率)
11722 - Joining with Friend You are going from Dhaka to Chittagong by train and you came to know one ...
- uva 11722 - Joining with Friend(概率)
题目连接:uva 11722 - Joining with Friend 题目大意:你和朋友乘火车,而且都会路过A市.给定两人可能到达A市的时段,火车会停w.问说两人能够见面的概率. 解题思路:y = ...
- 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 ...
- 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 ...
- LINQ之路13:LINQ Operators之连接(Joining)
Joining IEnumerable<TOuter>, IEnumerable<TInner>→IEnumerable<TResult> Operator 说明 ...
- SQL 基础学习(2) Joining 和function , 作业没有做,需要看百宝箱。NOsql的概念
SQL 基础学习(2) Joining 可以同时关联(joining)多张表进行复杂的查询. 相比于用Rails捞出数据再用Ruby进行过滤组合,使用SQL更加高效,节能. 以下是 users has ...
- UVA - 11722 Joining with Friend 几何概率
Joining with Friend You are going from Dhaka to Chittagong by train and you ...
随机推荐
- DragQueryFile
附件:http://files.cnblogs.com/xe2011/CSharp_DragQueryFile.rar using System.Runtime.InteropServices; th ...
- HTML5另类塔防游戏 -《三国战线》公布
关于本作 游戏介绍 本游戏是一款另类塔防游戏.本作以三国这段历史为题材,提供了从颍川之战到官渡之战.官渡之战到夷陵之战.夷陵之战到五丈原之战等15个关卡.在每一个关卡中,你会控制一名三国武将与出现的敌 ...
- [rxjs] Creating An Observable with RxJS
Create an observable var Observable = Rx.Observable; var source = Observable.create(function(observe ...
- oracle8
数据库管理 -- 管理表空间和数据文件 表空间是数据库的逻辑组成部分.从物理上讲,数据库数据存放在数据文件中:从逻辑上讲,数据库则是存放在表空间中,数据管理是以表空间管理的,表空间由一个或多个数据文件 ...
- CCProgressTimer用法
bool HelloWorld::init(){ if ( !CCLayerColor::initWithColor(ccc4(255, 255, 2555, 255))){ return false ...
- spring beans源码解读之--bean definiton解析器
spring提供了有两种方式的bean definition解析器:PropertiesBeanDefinitionReader和XmLBeanDefinitionReader即属性文件格式的bean ...
- 手动创建Servlet--J2EE学习笔记
Java Servlet 是运行在 Web 服务器或应用服务器上的程序,它是作为来自 Web 浏览器或其他 HTTP 客户端的请求和 HTTP 服务器上的数据库或应用程序之间的中间层. 使用 Serv ...
- oracle数据库敏感操作前创建还原点
我们都知道,在vmware虚拟机中有一个拍摄快照的功能,我们可以把系统此时的状态保存下来,一方后面遇到不测事件,也好将系统还原,oracle中也有类似功能. 首先创建一张学生表: 向学生表中插入一条数 ...
- Android(java)学习笔记178:BroadcastReceiver之 自定义广播
广播使用: 电台:对外发送信号.---------电台发送广播(可以自定义) 收音机:接收电台的信号.-----广播接收者 这里,我们就说明自定 ...
- linux下安装apache2.2.27
1.首先下载httpd-2.2.27.tar.gz用linux命令下载 wget http://mirrors.cnnic.cn/apache//httpd/httpd-2.2.27.tar.gz 2 ...