zoukankan      html  css  js  c++  java
  • HDU2056(rectangles)

    Rectangles

    Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
    Total Submission(s): 19299    Accepted Submission(s): 6255

    Problem Description

    Given two rectangles and the coordinates of two points on the diagonals of each rectangle,you have to calculate the area of the intersected part of two rectangles. its sides are parallel to OX and OY .

    Input

    Input The first line of input is 8 positive numbers which indicate the coordinates of four points that must be on each diagonal.The 8 numbers are x1,y1,x2,y2,x3,y3,x4,y4.That means the two points on the first rectangle are(x1,y1),(x2,y2);the other two points on the second rectangle are (x3,y3),(x4,y4).

    Output

    Output For each case output the area of their intersected part in a single line.accurate up to 2 decimal places.

    Sample Input

    1.00 1.00 3.00 3.00 2.00 2.00 4.00 4.00 5.00 5.00 13.00 13.00 4.00 4.00 12.50 12.50

    Sample Output

    1.00 56.25

    Author

    seeyou

    Source

    校庆杯Warm Up

    Recommend

    linle   |   We have carefully selected several similar problems for you:  20572058206220602059

    Statistic | Submit | Discuss | Note

     

    这道题乍一看挺复杂,但是是有技巧的。只需要将4个横坐标和4个纵坐标排序然后就可简化成一种很容易计算的形式。还要注意首先要排除没有交叉部分的情况。

     

     1 #include<stdio.h>
     2 #include<algorithm>
     3 using namespace std;
     4 
     5 int main()
     6 {
     7     double x[4], y[4];
     8     while(~scanf("%lf%lf%lf%lf%lf%lf%lf%lf", &x[0], &y[0], &x[1], &y[1], &x[2], &y[2], &x[3], &y[3])) {
     9         double minx1 = min(x[0], x[1]), maxx1 = max(x[0], x[1]), minx2 = min(x[2], x[3]), maxx2 = max(x[2], x[3]);
    10         double miny1 = min(y[0], y[1]), maxy1 = max(y[0], y[1]), miny2 = min(y[2], y[3]), maxy2 = max(y[2], y[3]);
    11         if(minx1 >= maxx2 || maxx1 <= minx2 || maxy1 <= miny2 || miny1 >= maxy2) printf("%.2lf
    ", 0);
    12         else {
    13             sort(x, x + 4);
    14             sort(y, y + 4);
    15             printf("%.2lf
    ", (x[2] - x[1]) * (y[2] - y[1]));
    16         }
    17     }
    18 }
    View Code

     

     

  • 相关阅读:
    Spring常用注解
    mybatis注解映射的简单分类
    Java框架中各层作用简述
    maven中groupId和artifactId的含义
    mybatis缓存
    防盗链的基本原理
    将部分字符串转化成JsonArray
    风螺旋线的进入
    3D转弯保护区长啥样?
    风螺旋线公切线的算法
  • 原文地址:https://www.cnblogs.com/xzrmdx/p/5196052.html
Copyright © 2011-2022 走看看