2018 Hangzhou Electric Multi-school third field 1007 (Convex package, pole angle sort)

Source: Internet
Author: User
Tags pow

#include <bits/stdc++.h>
using namespace Std;
typedef const long Long LL;
struct node
{
int x, y;
int POS;
}PLANE[200020],TUBAO[200020],STT;
int top;
int n;
Long Long multi (node A,node b,node c)
{
ll mianji=1ll* (a.x-c.x) * (B.Y-C.Y) -1ll* (A.Y-C.Y) * (b.x-c.x);//area Formula judging positive negative value
return Mianji;
}
BOOL CMP (node A,node b)
{
if (A.X==B.X&AMP;&AMP;A.Y==B.Y)
Return a.pos>b.pos;//repeating point, dictionary large row in front (here if the dictionary is small, WA, the reason is unknown)
if (!multi (stt,b,a))//two points equal to the line slope of the origin, i.e. three-point collinear
Return Pow (a.x-stt.x,2) +pow (a.y-stt.y,2) <pow (b.x-stt.x,2) +pow (b.y-stt.y,2);
And the origin of the distance near the row in front
return multi (stt,b,a) >0;//multi is a positive description of the order of the mating convex hull before B (a under B if the ordinate is equal to a horizontal axis smaller)
}
void Graham ()
{
TUBAO[1]=PLANE[1];
TUBAO[2]=PLANE[2];
top=3;
for (int i=3;i<=n;i++)
{
while (Top>2&&multi (tubao[top-2],plane[i],tubao[top-1]) <=0)
{
if (multi (tubao[top-2],plane[i],tubao[top-1)) <0| | Plane[i].pos<tubao[top-1].pos)//dealing with dictionary order problems
The point should join the convex hull or the 2nd coincident before the 2nd in the stack, but the dictionary is pre-ordered.
top--;
Else
Break
}
tubao[top++]=plane[i];//using stacks to simulate joining convex hull sequence
}
for (int i=1;i<top;i++)
{
printf ("%d%c", tubao[i].pos,i==top-1? \ n ': ');
}
}
int main ()
{
int t;
scanf ("%d", &t);
while (t--)
{
scanf ("%d", &n);
int x, y;
for (int i=1;i<=n;i++)
{
scanf ("%d%d", &x,&y);
Plane[i].x=x;
Plane[i].y=y;
Plane[i].pos=i;
}
STT=PLANE[1];
Sort (plane+2,plane+1+n,cmp);//starting point does not participate in sorting
Graham ();
}
return 0;
}

Coordinate sort to be mended

2018 Hangzhou Electric Multi-school third field 1007 (Convex package, pole angle sort)

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.