zoukankan      html  css  js  c++  java
  • 【蓝桥杯,几何问题】试题 基础练习 矩形面积交

    在这里插入图片描述
    在这里插入图片描述
    实现代码:

    import java.util.Map;
    import java.util.Scanner;
    
    public class Main {
    
    
        public static void main(String[] args) {
            Scanner sc = new Scanner(System.in);
            double x1 = 0, y1 = 0, x2 = 0, y2 = 0, x3 = 0, y3 = 0, x4 = 0, y4 = 0;
            x1 = sc.nextDouble();
            y1 = sc.nextDouble();
            x2 = sc.nextDouble();
            y2 = sc.nextDouble();
            x3 = sc.nextDouble();
            y3 = sc.nextDouble();
            x4 = sc.nextDouble();
            y4 = sc.nextDouble();
            double a1 = Math.max(Math.min(x1, x2), Math.min(x3, x4));
            double b1 = Math.max(Math.min(y1, y2), Math.min(y3, y4));
            double a2 = Math.min(Math.max(x1, x2), Math.max(x3, x4));
            double b2 = Math.min(Math.max(y1, y2), Math.max(y3, y4));
            double res = 0f;
            if (a2 - a1 > 0 && b2 - b1 > 0) {
                res = (a2 - a1) * (b2 - b1);
            }
            System.out.println(String.format("%.2f", res));
            sc.close();
        }
    }
    
  • 相关阅读:
    word-wrap和word-break的区别
    transform 二维转变
    过渡
    新闻下滑导航案例
    background-origin,clip
    边框图片
    背景样式
    线性渐变与径向渐变与重复渐变
    边框阴影
    盒模型和圆角
  • 原文地址:https://www.cnblogs.com/HoweZhan/p/12580748.html
Copyright © 2011-2022 走看看