https://leetcode.com/problems/minimum-area-rectangle/
class Solution {
public:
int minAreaRect(vector<vector<int>>& points) {
bool found = false;
int psize = points.size(), min_area = INT_MAX;
set<pair<int, int>> setp;
for(auto p:points){
setp.insert(pair<int, int>(p[0], p[1]));
}
for(int i=0; i<psize; i++){
for(int j=i+1; j<psize; j++){
int x1=points[i][0], y1=points[i][1], x2=points[j][0], y2=points[j][1];
if(x1==x2 || y1==y2) continue; //不能在一条线上
if(abs(x1-x2)*abs(y1-y2)>min_area) continue;
if(setp.find(pair<int, int>(x1,y2))!=setp.end()&&setp.find(pair<int, int>(x2,y1))!=setp.end()){ //矩形的另外两个点也存在
found = true;
min_area = min(min_area, abs(x1-x2)*abs(y1-y2));
}
}
}
if(found==false) return 0;
return min_area;
}
};