I need to find the maximum number of rectangles from a given set of coordinates.
Consider the following coordinates specified in the coordinate system XY 3 10, 3 8, 3 6, 3 4, 3 0, 6 0, 6 4, 6 8, 6 10,
How can I find if the following coordinates form a rectangle (3,0) (3,4) (6,4) (6,0)
Runtime Limit: 0.1s
thanks
, (x1, y1) (x2, y2) angular. (x1, y2) (x2, y1) , angular. , , angular, 2.
angular, X Y.
C++:
answer = 0; set<pair<int, int>> points; for(auto i=points.begin(); i!=std::prev(points.end()); i++) { for(auto j=i+1; j!=points.end(); j++) { pair<int, int> p1 = *i; pair<int, int> p2 = *j; pair<int, int> p3 = make_pair(p1.first, p2.second); pair<int, int> p4 = make_pair(p2.first, p1.second); if(points.find(p3) != points.end() && points.find(p4) != points.end()) ++answer; } } return answer/2;
"y", "x". :
3: [0,4,6,8,10] 6: [0,4,8,10]
: [0,4,8,10]
:
[0,4] => (3,0), (3,4), (6,0), (6,4) [0,8] => (3,0), (3,8), (6,0), (6,8) [4,8] => (3,4), (3,8), (6,4), (6,8) ...
, , x, y.
, 4 :
[0] = a [1], a [2] = a [3], a [4] = a [5]
,
, , .. .
, . , , .
, . , , , .