矩形相交问题
作者:互联网
class Solution {
public:
int computeArea(int A, int B, int C, int D, int E, int F, int G, int H) {
using ll = long long;
ll x = static_cast<ll>(min(C, G)) - static_cast<ll>(max(A, E));
ll y = static_cast<ll>(min(D, H)) - static_cast<ll>(max(B, F));
if(x < 0 || y < 0) x = y = 0;
ll rec1 = abs(D-B)*abs(C-A);
ll rec2 = abs(H-F)*abs(G-E);
ll ans = rec1 - x*y + rec2;
return static_cast<int>(ans);
}
};
class Solution {
public:
bool isRectangleOverlap(vector<int>& rec1, vector<int>& rec2) {
return min(rec1[2], rec2[2]) > max(rec1[0], rec2[0]) &&
min(rec1[3], rec2[3]) > max(rec1[1], rec2[1]);
}
};
标签:rec1,int,ll,相交,问题,cast,static,rec2,矩形 来源: https://www.cnblogs.com/littleorange/p/12527142.html