题目链接

题意:

  两个人坐火车, 在某个城市到站的时间段分别为[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. MVC 音乐商店 第 9 部分: 注册和结帐

    MVC 音乐商店是介绍,并分步说明了如何使用 ASP.NET MVC 和 Visual Studio 为 web 开发教程应用程序. MVC 音乐商店是一个轻量级的示例存储实现它卖音乐专辑在线,并实现 ...

  2. java数组的拷贝四种方法:for、clone、System.arraycopy、arrays.copyof

    public class ArrayCopy{ public static void main(String []args){ int []a = {1,3,4,5}; toPrint(a); int ...

  3. 基于单个 div 的 CSS 画图

    原文: Single Div Drawings with CSS 译文: 基于单个 div 的 CSS 画图 译者: 前端外刊评论 译注:通读本文,强烈地感受到了技术与艺术的结合.赞作者的这句话:Re ...

  4. careercup-链表 2.7

    2.7 编写一个函数,检查链表是否为回文. 思路:1)可以利用链表中的元素采用头插法创建一个新的链表,然后比较两个链表的元素是否相等.   2)利用快慢指针,将链表后半部分逆转之后,比较前半部分与后半 ...

  5. windows修改mysql默认字符集不成功

    今天下午弄了半天,终于把mysql的默认字符集弄成了, 按照网上的说法,什么修改mysql下面的my.ini文件,把参数设置成utf-8,我反复操作,结果都是不成功,后来我把mysql5.0卸载了,网 ...

  6. Android(java)学习笔记186:对ListView等列表组件中数据进行增、删、改操作

    1.ListView介绍 解决大量的相似的数据显示问题 采用了MVC模式: M: model (数据模型) V:  view  (显示的视图) C: controller 控制器 入门案例: acit ...

  7. Dom4j解析Xml文件,Dom4j创建Xml文件

    Dom4j解析Xml文件,Dom4j创建Xml文件 >>>>>>>>>>>>>>>>>>&g ...

  8. 过滤器(filter)实现用户登录拦截

    过滤器(filter)实现用户登录拦截 >>>>>>>>>>>>>>>>>>>> ...

  9. H TML5 之 (5) 一个在线画图板

    这里加入了点难度了,增加了对HTML很多时间的把握,对象的把握 index.html <!DOCTYPE HTML> <html> <head> <title ...

  10. [Mime] 在c#程序中放音乐的帮助类 (转载)

    using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.M ...