determine whether the rectangle, must meet the different 4 points, there are 4 edges (not coincident), the edge of the vector only two, and two vectors perpendicular;
You can meet these conditions.
Small Knowledge Points:
Two vectors perpendicular (x1,y1), (x2,y2) x1 * x2 + y1 * y2 = = 0;
Two vectors parallel (x1,y2), (x2,y2) x1 * y2-x2 * y2 = 0;
#1040: Rectangle JudgingTime limit: 1000ms single point time limit: 1000ms memory limit: 256MB description
The 4 lines on the plane are given to determine whether the 4 segments are exactly enclosed in a rectangle with an area greater than 0.
Input
The first line of input is an integer T (1<=t<=100), which represents the number of test data.
Each set of data contains 4 rows, each containing 4 integers x1, y1, x2, y2 (0 <= x1, y1, x2, y2 <= 100000), where (x1, y1), (X2,y2) represents two endpoints of a line segment.
Output
Each set of data outputs a row of Yes or no, indicating whether the input 4 segments are exactly rectangular.
-
-
Sample input
-
-
30 0 0 11 0 1 10 1 1 11 0 0 00 1 2 31 0 3 23 2 2 31 0 0 10 1 1 01 0 2 02 0 1 11 1 0 1
-
-
Sample output
-
Yesyesno
1 classNode {2 Public:3 intx, y;4 Node () {}5Node (intXinty): x (x), Y (y) {}6 BOOL operator< (Constnode& RHS)Const {7 return(x = = rhs.x)? Y < Rhs.y:x <rhs.x;8 }9 Ten BOOL operator== (Constnode& RHS)Const { One returnx = = Rhs.x && y = =Rhs.y; A } - }; - the classLine { - Public: - Node l1,l2; - Line () {} + Line (Node l1,node L2): L1 (L1), L2 (L2) {} - BOOL operator< (Constline& RHS)Const { + returnL1 = = RHS. L1? L2 < RHS. L2:l1 <RHS. L1; A } at }; - - intMain () { - intN; - //FR ("1.txt"); -CIN >>N; in while(n--) { - Set<Node> S;//vector for storing edges to Set<Node> Point;//4 points of Storage point +Vector<node> V;//used to sort the edges, because the point of the given edge is uncertain - Set<Line> L;//Storage Edge 4 edges theREP (I,4) { * intX1,y1,x2,y2; $ v.clear ();Panax NotoginsengCIN >> x1 >> y1 >> x2 >>Y2; - Point.insert (Node (x1,y1)); the Point.insert (Node (X2,y2)); + V.push_back (Node (x1,y1)); A V.push_back (Node (X2,y2)); the sort (V.begin (), V.end ()); +S.insert (Node (v[1].x-v[0].x,v[1].y-v[0].y)); -L.insert (Line (v[0],v[1])); $ } $ if(s.size () = =2&& point.size () = =4&& l.size () = =4) { - //the next step is to determine the vertical -Node now[2]; the Set<node>::iterator Iter =S.begin (); -now[0] = *iter++;Wuyinow[1] = *Iter; the if(now[0].x * now[1].x + now[0].Y * now[1].y = =0) { -cout <<"YES"<<Endl; Wu}Elsecout <<"NO"<<Endl; - } About Elsecout <<"NO"<<Endl; $ } -}
Hihocoder hold Judgment (calculate geometry)