zoukankan      html  css  js  c++  java
  • 基础练习 矩形面积交

    问题描述
      平面上有两个矩形,它们的边平行于直角坐标系的X轴或Y轴。对于每个矩形,我们给出它的一对相对顶点的坐标,请你编程算出两个矩形的交的面积。
    输入格式
      输入仅包含两行,每行描述一个矩形。
      在每行中,给出矩形的一对相对顶点的坐标,每个点的坐标都用两个绝对值不超过10^7的实数表示。
    输出格式
      输出仅包含一个实数,为交的面积,保留到小数后两位。
    样例输入
    1 1 3 3
    2 2 4 4
    样例输出
    1.00
    import java.text.DecimalFormat;
    import java.text.NumberFormat;
    import java.util.ArrayList;
    import java.util.Scanner;  
    
        public class Main{   
            public static void main(String[] args){  
                Scanner input = new Scanner(System.in);
                double a1,a2,b1,b2;
                double x1,x2,y1,y2;
                a1 = input.nextDouble();
                b1 = input.nextDouble();
                a2 = input.nextDouble();
                b2 = input.nextDouble();
                x1 = input.nextDouble();
                y1 = input.nextDouble();
                x2 = input.nextDouble();
                y2 = input.nextDouble();
                double n1,m1,n2,m2;
                n1 = Math.max(Math.min(x1, x2), Math.min(a1, a2));
                m1 = Math.max(Math.min(y1, y2), Math.min(b1, b2));
                n2 = Math.min(Math.max(x1, x2), Math.max(a1, a2));
                m2 = Math.min(Math.max(y1, y2),Math.max(b1, b2));
                if(n2>n1&&m2>m1){
                    NumberFormat format = new DecimalFormat("#.00");
                    System.out.println(format.format((m2-m1)*(n2-n1)));
                    
                }
                else{
                    System.out.println("0.00");
                }
                
            }
     }  
  • 相关阅读:
    Socket原理与编程基础
    Hello cnblogs
    c# List 分页问题
    chrome下载Word失败问题
    前端时间Date显示问题踩坑
    Vue跳转同一界面多次,使用不同数据进行渲染
    Hadoop在Linux环境下的配置
    RabbitMQ下载安装
    Codeforces 527 C. Glass Carving
    python压缩、解压文件
  • 原文地址:https://www.cnblogs.com/lolybj/p/6505853.html
Copyright © 2011-2022 走看看