zoukankan      html  css  js  c++  java
  • 计算几何:POJ

    It's raining outside. Farmer Johnson's bull Ben wants some rain to water his flowers. Ben nails two wooden boards on the wall of his barn. Shown in the pictures below, the two boards on the wall just look like two segments on the plane, as they have the same width.


    Your mission is to calculate how much rain these two boards can collect.
    Input

    The first line contains the number of test cases.
    Each test case consists of 8 integers not exceeding 10,000 by absolute value, x 1, y 1, x 2, y 2, x 3, y 3, x 4, y 4. ( x 1, y 1), ( x 2, y 2) are the endpoints of one board, and ( x 3, y 3), ( x 4, y 4) are the endpoints of the other one.

    Output

    For each test case output a single line containing a real number with precision up to two decimal places - the amount of rain collected.

    Sample Input

    2
    0 1 1 0
    1 0 2 1
    
    0 1 2 1
    1 0 1 2
    

    Sample Output

    1.00
    0.00
    首先,要排除两线平行或其中一条线与地面平行的情况,此时无法积水。
    然后如果两个线段没有交点,那么同样无法积水。
    计算出交点后,用这个交点替换每条线中y坐标较小的点。
    这个过程如下图所示:


    也就是将图案变成一个勾。
    由于我们是舍弃了y坐标较小点,所以无论什么情况,我们都尽可能选择了开口向上的图案。
    判断积水的条件也很简单,只要勾形中的交点的y坐标比另外两个点的y坐标都小,就能积水。
    积水用海伦公式就能算出来了。
    这样就能够ac?不存在的,看似滴水不漏,但实际上“滴水不漏”就是个错误。
    注意题意不仅要能存水,也要能进水,水是从上方垂直流下的。
    0 0 10 10
    0 0 9 8
    这一组数据能够构造出一个勾形水槽,但如果画图会发现第一条线完全位于在第二条线上方,也就是说,你的水槽虽然能存水,但水是进不去的,所以答案为0.00。
    那么我们要在上述基础上再度判断,是否出现覆盖现象。
    几度修改后 still wrong
    只能说这道题的思路就是如此了,但要挑很多细节,要保精度,还要注意eps。

  • 相关阅读:
    C++ 实现B+树
    SSM项目--
    spring+mybatis使用MapperScannerConfigurer简化配置
    SpringMVC复习总结
    MyBatis复习总结
    ajax
    几种常用页面的跳转
    MyShop-不用框架的基础javaweb项目
    jsp
    Guava 工具类之joiner的使用
  • 原文地址:https://www.cnblogs.com/qq936584671/p/7801272.html
Copyright © 2011-2022 走看看