【蓝桥杯,几何问题】试题 基础练习 矩形面积交

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

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();
    }
}
posted @ 2020-03-27 13:17  bestwell  阅读(174)  评论(0编辑  收藏  举报