C. Nearest vectors--cf598c (Extreme angle sort)

Source: Internet
Author: User

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)

Related Article

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.