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 ...
随机推荐
- Spring 4.x org.springframework.http.converter.json.MappingJacksonHttpMessageConverter ClassNotFoundException:
Spring 4.x The first major version of Jackson is no longer supported in Spring 4. The class you want ...
- Cocos2d-x 3.1.1 学习日志4--cocos2d-x解决中文乱码问题的几种办法
做个打飞机的游戏,由于版本号太新,网上基本没有教教程,我的版本号是cocos2d-x 3.1.1的.今天遇到cocos2dx中中文乱码的问题.无奈仅仅好Google百度寻求答案,明确了这个问题的缘由. ...
- 单片机IO口驱动能力
以STM32的IO口为例,最大的输出电流和灌入电流在芯片手册上都有说明.单个IO口一般都是十几mA到几十mA,同时总的VDD电流也有限制,大概为150mA.所以单片机驱动外设时,如果不是信号型而是功率 ...
- 基于单个 div 的 CSS 画图
原文: Single Div Drawings with CSS 译文: 基于单个 div 的 CSS 画图 译者: 前端外刊评论 译注:通读本文,强烈地感受到了技术与艺术的结合.赞作者的这句话:Re ...
- one problem about Apple Keychain in use
解决方案 Add Security.framework, then rebuild. Sometimes I find I have to build clean and then rebuild. ...
- cocos2dx游戏项目总结(持续更新)
1.在一个layer里面,尽量只使用一种按钮类型.如MenuItem or CCControlButton.因为这两种按钮的优先级不同,在使用过程中会互相影响到事件触发的先后顺序. 2.细节的问题要一 ...
- 精《记叙“tom”4年的软件开发之旅》
1.引言 本篇文章是记叙tom四年的软件开发从业经历,虽然他资历不长,况且本身也是个菜鸟,但他也曾有过荣誉.迷茫.困惑与选择,在这里他希望通过自己所经历过的事情分享给大家,给那些真正热爱软件开发的同学 ...
- 安装Oracle数据库和PLSQL连接数据库
首先在Oracle官网上下载: 安装前要注意:将win64_11gR2_database_2of2中的\win64_11gR2_database_2of2\database\stage\Compone ...
- jquery.validate中使用remote,remote相同值不校验问题解决
jquery.validate中使用remote, remote相同值不校验问题解决 >>>>>>>>>>>>>>& ...
- ADO.Net技术
Connection对象 1.连接数据库 通过SqlConnection对象的State属性判断数据库的连接状态: public override ConnectionState State{ get ...