Http://codeforces.com/problemset/problem/598/C
The main idea is to give you the starting point of a vector vector is the minimum output of the 0,0 from the beginning of the (*) vector
This is the first contact with the polar angle.
The distance from a point to the origin of a function image is the polar diameter, and the angle between the polar diameter and the x-axis is the polar angle.
Sorting by polar angle is from the rightmost beginning of the third quadrant to the far right of the second quadrant, counterclockwise
The smallest angle difference.
But the card accuracy problem to replace the double with a long double is good (I do not know why)
#include <stdio.h>#include<math.h>#include<algorithm>#include<iostream>#defineINF 0x3f3f3f3f3using namespacestd;structnode{intX,y,j;Long DoubleK;} a[101000];intCMP (node C,node d) {returnc.k<D.K;}intMain () {intN; while(SCANF ("%d", &n)! =EOF) { for(intI=1; i<=n;i++) {scanf ("%d%d",&a[i].x,&a[i].y); A[I].K=atan2 (a[i].y,a[i].x); A[I].J=i; } sort (A+1, A +1+n,cmp); a[0].k=A[N].K; a[0].j=A[N].J; intxx=0, yy=0; Long Doublemin=INF; for(intI=1; i<=n;i++) { Long Doublejiao=a[i].k-a[i-1].K; if(jiao<0) Jiao+=acos (-1.0)*2; if(jiao<Min) {Min=Jiao; XX=A[I].J; YY=a[i-1].J; }} printf ("%d%d\n", Xx,yy); } return 0;}
C. Nearest vectors--cf598c (Extreme angle sort)