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

     

     

  • 相关阅读:
    ACM ICPC 2008–2009 NEERC MSC A, B, C, G, L
    POJ 1088 滑雪 DP
    UVA 11584 最短回文串划分 DP
    POJ 2531 Network Saboteur DFS+剪枝
    UVa 10739 String to Palindrome 字符串dp
    UVa 11151 Longest Palindrome 字符串dp
    UVa 10154 Weights and Measures dp 降维
    UVa 10271 Chopsticks dp
    UVa 10617 Again Palindrome 字符串dp
    UVa 10651 Pebble Solitaire 状态压缩 dp
  • 原文地址:https://www.cnblogs.com/xzrmdx/p/5196052.html
Copyright © 2011-2022 走看看