#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&&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)