Codeforces beta round #97 (Div. 2) (determine the square and rectangle)

Source: Internet
Author: User
D. rectangle and squaretime limit per test

2 seconds

Memory limit per test

256 megabytes

Input

Standard Input

Output

Standard output

Little Petya very much likes Rectangles and especially squares. recently he has initialized ed 8 points on the plane as a gift from his mother. the points are pairwise distinct. petya decided to split them into two sets each containing 4 points so that the points
From the first set lay at the vertexes of some square and the points from the second set lay at the vertexes of a rectangle. each point of initial 8 shoshould belong to exactly one set. it is acceptable for a rectangle from the second set was also a square. if
There are several partitions, Petya will be satisfied by any of them. help him find such partition. note that the rectangle and the square from the partition shocould have non-zero areas. the sides of the figuresdo
Not have to be parallel to the coordinate axes, though it might be the case.

<P = ""> <p = "">

Input

<P = "">

You are given 8 pairs of integers, a pair per line-the coordinates of the points Petya has. The absolute value of all coordinates does not exceed 104.
It is guaranteed that no two points coincide.

<P = ""> <p = "">

Output

<P = "">

Print in the first output line "yes" (without the quotes), if the desired partition exists. In the second line output 4 space-separated numbers-Point Indexes
From the input, which lie at the vertexes of the square. the points are numbered starting from 1. the numbers can be printed in any order. in the third line print the indexes of points lying at the vertexes of a rectangle in the similar format. all printed
Numbers shoshould be pairwise distinct.

If the required partition does not exist, the first line shoshould contain the word "no" (without the quotes), after which no output is needed.

<P = ""> <p = "">

Sample test (s)

<P = ""> <p = "">

Input
0 010 1110 00 111 12 22 11 2
Output
YES5 6 7 81 2 3 4
Input
0 01 12 23 34 45 56 67 7
Output
NO
Input
0 04 44 00 41 22 33 22 1
Output
YES1 2 3 45 6 7 8

<P = ""> <p = "">

Note

<P = "">

Pay attention to the Third example: the figures do not necessarily have to be parallel to the coordinate axes.

Include <cstdio> # include <cmath> # include <algorithm> Using STD: sort; # define EPS 1e-8 # define zero (x)> 0? (X):-(x) <EPS) struct point {Double X, Y; int ID ;}; struct line {point A, B ;}; // calculate cross product (P1-P0) x (P2-P0) Double xmult (point P1, point P2, point P0) {return (p1.x-ready X) * (p2.y-ready y) -(p2.x-Direction X) * (p1.y-direction y);} double xmult (double X1, double Y1, double X2, double Y2, double x0, double y0) {return (x1-x0) * (y2-y0)-(x2-x0) * (y1-y0);} // calculate the dot product (P1-P0 ). (P2-P0) Double dmult (point P1, point P2, point P0) {return (p1. X-p0.x) * (p2.x-0000x) + (p1.y-0000y) * (p2.y-0000y);} double dmult (double X1, double Y1, double X2, double Y2, double x0, double y0) {return (x1-x0) * (x2-x0) + (y1-y0) * (y2-y0);} // two points away from double distance (point P1, point P2) {return SQRT (p1.x-p2.x) * (p1.x-p2.x) + (p1.y-p2.y) * (p1.y-p2.y);} double distance (double X1, double Y1, double X2, double Y2) {return SQRT (x1-x2) * (x1-x2) + (y1-y2) * (y1-y2);} // returns a three-point collinearity int dots_inline (point P1, Point P2, point P3) {return zero (xmult (P1, P2, P3);} int dots_inline (double X1, double Y1, double X2, double Y2, double X3, double Y3) {return zero (xmult (x1, Y1, X2, Y2, X3, Y3);} // determine whether the vertex is on the online segment, include the endpoint int dot_online_in (point P, line L) {return zero (xmult (P, L. a, L. b) & (L. a. x-p.x) * (L. b. x-p.x) <EPS & (L. a. y-p.y) * (L. b. y-p.y) <EPS;} int dot_online_in (point P, point L1, point L2) {return zero (xmult (p, L1, L2) & (l1.x-P. x) * (l2.x-P. X) <EPS & (l1.y-P. y) * (l2.y-P. y) <EPS;} int dot_online_in (Double X, Double Y, double X1, double Y1, double X2, double Y2) {return zero (xmult (X, Y, X1, y1, X2, Y2) & (x1-x) * (x2-x) <EPS & (y1-y) * (y2-y) <EPS ;}// determine whether the spot is on the online segment, the endpoint int dot_online_ex (point P, line L) {return dot_online_in (P, L )&&(! Zero (P. x-l.a.x) |! Zero (P. y-l.a.y ))&&(! Zero (P. x-l. B .x) |! Zero (P. y-l. B .y);} int dot_online_ex (point P, point L1, point L2) {return dot_online_in (p, L1, L2 )&&(! Zero (P. x-l1.x) |! Zero (P. y-l1.y ))&&(! Zero (P. x-l2.x) |! Zero (P. y-l2.y);} int dot_online_ex (Double X, Double Y, double X1, double Y1, double X2, double Y2) {return dot_online_in (X, Y, X1, Y1, X2, y2 )&&(! Zero (x-x1) |! Zero (y-y1 ))&&(! Zero (x-x2) |! Zero (y-y2);} // returns 0int same_side (point P1, point P2, line L) {return xmult (L. a, P1, L. b) * xmult (L. a, P2, L. b)> EPS;} int same_side (point P1, point P2, point L1, point L2) {return xmult (L1, P1, L2) * xmult (L1, P2, l2)> EPS;} // determine the different sides of the two online segments. The 0int opposite_side (point P1, point P2, line L) {return xmult (L. a, P1, L. b) * xmult (L. a, P2, L. b) <-EPS;} int opposite_side (point P1, point P2, point L1, point L2) {return xmult (L1, P1, L2) * xmult (L1, P2, L2) <-EPS;} // determine two straight-line parallel int parallel (line U, line V) {return zero (U. a. x-u. B .x) * (v. a. y-v. B .y)-(V. a. x-v. B .x) * (U. a. y-u. B .y);} int parallel (point u1, point U2, point V1, point V2) {return zero (u1.x-u2.x) * (v1.y-v2.y) -(v1.x-v2.x) * (u1.y-u2.y);} // judge two straight lines vertical int perpendicular (line U, line V) {return zero (U. a. x-u. B .x) * (v. a. x-v. B .x) + (U. a. y-u. B .y) * (v. a. y-v. B .y);} int perpendicular (point u1, point U2, P Oint V1, point V2) {return zero (u1.x-u2.x) * (v1.x-v2.x) + (u1.y-u2.y) * (v1.y-v2.y ));} // determine the intersection of two line segments, including the endpoint and partial coincidence int intersect_in (line U, line V) {If (! Dots_inline (U. A, U. B, V. a) |! Dots_inline (U. A, U. B, V. B) return! Same_side (U. A, U. B, v )&&! Same_side (v. a, V. b, U); Return dot_online_in (U. a, v) | dot_online_in (U. b, v) | dot_online_in (v. a, u) | dot_online_in (v. b, U);} int intersect_in (point u1, point U2, point V1, point V2) {If (! Dots_inline (U1, U2, V1) |! Dots_inline (U1, U2, V2) return! Same_side (U1, U2, V1, V2 )&&! Same_side (V1, V2, u1, U2); Return dot_online_in (U1, V1, V2) | dot_online_in (U2, V1, V2) | dot_online_in (V1, u1, U2) | dot_online_in (V2, u1, U2);} // identifies the intersection of two line segments, excluding the endpoint and partial coincidence int intersect_ex (line U, line V) {return opposite_side (U. a, U. b, v) & opposite_side (v. a, V. b, U);} int intersect_ex (point u1, point U2, point V1, point V2) {return opposite_side (U1, U2, V1, V2) & opposite_side (V1, v2, u1, U2) ;}// calculate the intersection of two straight lines. Check whether the line is parallel in advance! // Determine the intersection of line segments separately (parallel or not at the same time !) Point intersection (line U, line V) {point ret = u. a; Double T = (U. a. x-v.a.x) * (v. a. y-v. B .y)-(U. a. y-v.a.y) * (v. a. x-v. B .x)/(U. a. x-u. B .x) * (v. a. y-v. B .y)-(U. a. y-u. B .y) * (v. a. x-v. B .x); ret. X + = (U. b. x-u.a.x) * t; ret. Y + = (U. b. y-u.a.y) * t; return ret;} point intersection (point u1, point U2, point V1, point V2) {point ret = U1; Double T = (u1.x-v1.x) * (v1.y-v2.y)-(u1.y-v1.y) * (v1.x-v2.x)/(u1.x-u2.x) * (v1.y-v2.y)-(u1.y-U2. Y) * (v1.x-v2.x); ret. X + = (u2.x-u1.x) * t; ret. Y + = (u2.y-u1.y) * t; return ret;} // point ptoline (point P, line L) {point T = P; T. X + = L. a. y-l. B .y, T. Y + = L. b. x-l.a.x; return intersection (P, T, L. a, L. b);} Point ptoline (point P, point L1, point L2) {point T = P; T. X + = l1.y-l2.y, T. Y + = l2.x-l1.x; return intersection (P, T, L1, L2);} // distance from a point to a straight line to double disptoline (point P, line L) {return FABS (xmult (P, L. a, L. b)/distance (L. a, L. B);} double disptoline (point P, point L1, point L2) {return FABS (xmult (p, L1, L2)/distance (L1, L2 );} double disptoline (Double X, Double Y, double X1, double Y1, double X2, double Y2) {return FABS (xmult (X, Y, X1, Y1, X2, Y2 )) /distance (x1, Y1, X2, Y2);} // point ptoseg (point P, line L) {point T = P; T. X + = L. a. y-l. B .y, T. Y + = L. b. x-l.a.x; If (xmult (L. a, T, P) * xmult (L. b, T, P)> EPS) return distance (P, L. a) <distance (P, L. B )? L. a: l. b; return intersection (P, T, L. a, L. b);} Point ptoseg (point P, point L1, point L2) {point T = P; T. X + = l1.y-l2.y, T. Y + = l2.x-l1.x; If (xmult (L1, T, P) * xmult (L2, T, P)> EPS) return distance (p, L1) <distance (p, L2 )? L1: L2; return intersection (P, T, L1, L2);} // distance from a point to a line segment to double disptoseg (point P, line L) {point T = P; T. X + = L. a. y-l. B .y, T. Y + = L. b. x-l.a.x; If (xmult (L. a, T, P) * xmult (L. b, T, P)> EPS) return distance (P, L. a) <distance (P, L. B )? Distance (P, L. a): distance (P, L. b); Return FABS (xmult (P, L. a, L. b)/distance (L. a, L. b);} double disptoseg (point P, point L1, point L2) {point T = P; T. X + = l1.y-l2.y, T. Y + = l2.x-l1.x; If (xmult (L1, T, P) * xmult (L2, T, P)> EPS) return distance (p, L1) <distance (p, L2 )? Distance (p, L1): distance (p, L2); Return FABS (xmult (p, L1, L2)/distance (L1, L2 );} // vector V uses P as the vertex to rotate the angle counterclockwise and enlarge the scale point rotate (point V, point P, double angle, double scale) {point ret = P; V. x-= P. x, V. y-= P. y; p. X = scale * Cos (angle); p. y = scale * sin (angle); ret. X + = v. x * P. x-v.y * P. y; ret. Y + = v. x * P. Y + v. y * P. x; return ret;} point P [10]; int set1 [10], set2 [10]; bool check (point P1, point P2, point P3, point P4) {double dis1 = Distance (P1, P2); double dis2 = distance (P2, P4); If (dis1! = Dis2) return false; double dis3 = distance (P4, P3); If (dis2! = Dis3) return false; double dis4 = distance (P3, P1); If (dis3! = Dis4) return false; If (! Zero (distance (P1, P4)-distance (P2, P3) return false; If (! Perpendicular (P1, P4, P2, P3) return false; P1 = P [set2 [1]; P2 = P [set2 [2]; p3 = P [set2 [3]; P4 = P [set2 [4]; dis1 = distance (P1, P2); dis2 = distance (P2, P4 ); dis3 = distance (P4, P3); dis4 = distance (P3, P1); If (dis1! = Dis3 | dis2! = Dis4) return false; If (! Zero (distance (P1, P4)-distance (P2, P3) return false; return true;} bool DFS (INT num, int index) {If (Num> 4) {bool mark [10] = {0 }; mark [set1 [1] = mark [set1 [2] = mark [set1 [3] = mark [set1 [4] = true; for (INT I = 1, j = 0; I <= 8; I ++) if (! Mark [I]) set2 [++ J] = I; If (check (P [set1 [1], p [set1 [2], P [set1 [3], p [set1 [4]) return true; return false;} If (index> 8) return false; set1 [num] = index; if (DFS (Num + 1, index + 1) return true; If (DFS (Num, index + 1) return true; return false ;} bool CMP (const point & A, const point & B) {if (. X = B. x) return. Y <B. y; return. x <B. x;} int main () {for (INT I = 1; I <= 8; I ++) {P [I]. id = I; scanf ("% lf", & P [I]. x, & P [I]. y);} Sort (p + 1, P + 9, CMP); If (DFS (1,1) {printf ("Yes \ n "); printf ("% d \ n", P [set1 [1]. ID, P [set1 [2]. ID, P [set1 [3]. ID, P [set1 [4]. ID); printf ("% d \ n", P [set2 [1]. ID, P [set2 [2]. ID, P [set2 [3]. ID, P [set2 [4]. ID); putchar ('\ n');} else printf ("NO \ n"); Return 0 ;}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.