求相交矩形的面积
1 class Solution { 2 public: 3 int computeArea(int A, int B, int C, int D, int E, int F, int G, int H) { 4 int dx = max(A,E); 5 int dy = max(B,F); 6 int ux = min(C,G); 7 int uy = min(D,H); 8 if(ux>dx&&uy>dy){ 9 return (C-A)*(D-B)+(G-E)*(H-F) - (ux - dx) * (uy - dy); 10 } 11 else return (C-A)*(D-B)+(G-E)*(H-F) ; 12 } 13 };
时间: 2024-10-27 07:23:02