zoukankan      html  css  js  c++  java
  • 5D

    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

    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

    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

    // 没考虑无相交区域
     1 #include<stdio.h>
     2 int main()
     3 {
     4     double x1,y1, x2,y2, x3,y3, x4,y4, a,b, t;
     5     while(scanf("%lf %lf %lf %lf %lf %lf %lf %lf", &x1,&y1,&x2,&y2,&x3,&y3,&x4,&y4)!=EOF)
     6     {
     7         if(x1>x2)
     8         { t=x2; x2=x1; x1=t; }
     9         if(y1>y2)
    10         { t=y2; y2=y1; y1=t; }
    11         if(x3>x4)
    12         { t=x4; x4=x3; x3=t; }
    13         if(y3>y4)
    14         { t=y4; y4=y3; y3=t; }
    15         a=x1-x4>x3-x2?x1-x4:x3-x2;
    16         b=y1-y4>y3-y2?y1-y4:y3-y2;
    17         printf("%.2f
    ", a*b);
    18     }
    19     return 0;
    20 }
    WA
    // 还是错得离谱 感觉没有智商T^T
     1 #include<stdio.h>
     2 int main()
     3 {
     4     double x1,y1, x2,y2, x3,y3, x4,y4, a,b, t;
     5     while(scanf("%lf %lf %lf %lf %lf %lf %lf %lf", &x1,&y1,&x2,&y2,&x3,&y3,&x4,&y4)!=EOF)
     6     {
     7         if(x1>x2)
     8         { t=x2; x2=x1; x1=t; }
     9         if(y1>y2)
    10         { t=y2; y2=y1; y1=t; }
    11         if(x3>x4)
    12         { t=x4; x4=x3; x3=t; }
    13         if(y3>y4)
    14         { t=y4; y4=y3; y3=t; }
    15         a=x1-x4>x3-x2?x1-x4:x3-x2;
    16         b=y1-y4>y3-y2?y1-y4:y3-y2;
    17         if(a>=0||b>=0) printf("0.00
    ");
    18         else printf("%.2f
    ", a*b);
    19     }
    20     return 0;
    21 }
    WA*2
    // 
     1 #include<stdio.h>
     2 int main()
     3 {
     4     double x1,y1, x2,y2, x3,y3, x4,y4, a,b, t;
     5     while(scanf("%lf %lf %lf %lf %lf %lf %lf %lf", &x1,&y1,&x2,&y2,&x3,&y3,&x4,&y4)!=EOF)
     6     {
     7         if(x1>x2)
     8         { t=x2; x2=x1; x1=t; }
     9         if(y1>y2)
    10         { t=y2; y2=y1; y1=t; }
    11         if(x3>x4)
    12         { t=x4; x4=x3; x3=t; }
    13         if(y3>y4)
    14         { t=y4; y4=y3; y3=t; }
    15         a=(x2<x4?x2:x4)-(x1>x3?x1:x3);
    16         b=(y2<y4?y2:y4)-(y1>y3?y1:y3);
    17         if(a<0||b<0) printf("0.00
    ");
    18         else printf("%.2f
    ", a*b);
    19     }
    20     return 0;
    21 }
    AC
  • 相关阅读:
    【web 安全测试Tools】BurpSuite 1.7.32及注册机【无后门版】
    【Kail 学习笔记】Dmitry信息收集工具
    【web 安全测试思路】图形验证码对服务器的影响
    【Kail 学习笔记】自用KAIL更新源
    ASP.NET动态网站制作(23)-- ADO.NET(2)
    ASP.NET动态网站制作(22)-- ADO.NET(1)
    ASP.NET动态网站制作(21)-- C#(4)
    ASP.NET动态网站制作(20)-- C#(3)
    ASP.NET动态网站制作(19)-- C#(2)
    ASP.NET动态网站制作(18)-- jq作业讲解及知识补充
  • 原文地址:https://www.cnblogs.com/goldenretriever/p/10355783.html
Copyright © 2011-2022 走看看