BASIC-18
这道题很有意思
矩形相交,其实就是找顶点
分为两种情况讨论
- 相交
- 不相交
其中相交的情况可以画图尝试归纳出相交矩形的对角坐标
我用的是左下角和右上角
找出最小和最大的比较关系
很容易就得出来了
记得保留小数的方法
import java.text.DecimalFormat;
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner scanner = new Scanner(System.in);
double x1 = scanner.nextDouble();
double y1 = scanner.nextDouble();
double x2 = scanner.nextDouble();
double y2 = scanner.nextDouble();
double x3 = scanner.nextDouble();
double y3 = scanner.nextDouble();
double x4 = scanner.nextDouble();
double y4 = scanner.nextDouble();
double s;
double a1 = Math.min(Math.max(x1, x2), Math.max(x3, x4));
double b1 = Math.min(Math.max(y1, y2), Math.max(y3, y4));
double a2 = Math.max(Math.min(x1, x2), Math.min(x3, x4));
double b2 = Math.max(Math.min(y1, y2), Math.min(y3, y4));
s = (b1 - b2) * (a1 - a2);
if (b1 > b2 && a1 > a2) {
DecimalFormat dFormat = new DecimalFormat("#.00");
System.out.print(dFormat.format(s));
} else {
System.out.print("0.00");
}
}
}
BASIC-19
是贪心
我代码路上的一道坎
打算找一天空闲时间专门学
BASIC-20
具象为字符串数组问题,然后分情况位次从高到低讨论
目前有了大体思路,正在慢慢实现
要去背单词了,明天继续加油
这道题几乎写完一个情况就要测试