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 ... 
随机推荐
- ElasticSearch怎样加入,检索数据
			Elasticsearch是一个分布式的文档(document)存储引擎.它能够实时存储并检索复杂数据结构--序列化的JSON文档.换言说,一旦文档被存储在Elasticsearch中,它就能够在集群 ... 
- easyui 很好很强大
			easyui 很好很强大 http://api.btboys.com/easyui/ 中文API教程 分页,拖动等效果很漂亮... 
- Android开发环境搭建(图文教程)
			昨天又搭建了一次Android的开发环境,尝试了好几种方式,也遇到了一些问题,在此分享一下. 注意:官网公布的最新版本号的SDK和ADT(23.0.0),对于和Eclipse集成的开发环境是有BUG存 ... 
- [TypeScript] Using Lodash in TypeScript with Typings and SystemJS
			One of the most confusing parts of getting started with TypeScript is figuring out how to use all th ... 
- servlet和手动创建servlet,断点调试
			1. 什么是Servlet Servlet是一种用Java语言编写的Web应用组件 Servlet主要用于动态网页输出,扩展了Web服务器的功能 Servlet由Servlet容器进行管理 2. ... 
- Servlet中文乱码解决方法
			程序中的输入输出都是以流的形式保存的,流中保存的实际上全都是字节文件. 字节流和字符流的区别: 在Java.io包中操作文件内容的主要有两大类:字节流.字符流,两类都分为输入和输出操作. 在字节流中输 ... 
- JS实例(一)
			一:单选按钮,选择同意,提交变为可用,反正提交不可用: HTML里面代码: <form id="f1" name="f1"> <input t ... 
- (转)Spring读书笔记-----Spring核心机制:依赖注入
			Java应用(从applets的小范围到全套n层服务端企业应用)是一种典型的依赖型应用,它就是由一些互相适当地协作的对象构成的.因此,我们说这些对象间存在依赖关系.加入A组件调用了B组件的方法,我们就 ... 
- PHP 数组转字符串,与字符串转数组
			implode 使用一个字符串将数组变成字符串 <?php $array = array('lastname', 'email', 'phone'); $comma_separated = im ... 
- Using load balance for thrift servers
			Software load balance .Nginx(http://nginx.org) 1.Install nginx download source code from http://ngin ... 
