lap Pool time limit: Ms | Memory limit: 65535 KB Difficulty: 4
Just finished HDU1392, see this problem, well, the original code changed on the past.
Test instructions said, will convex bag words is very simple, will not be difficult, this problem time limit is 4s, data 100, will cross product words three layer loop traversal can, two points determine a line segment to judge apart from the two points outside the other points are on the side of this line, is the two points are convex package on the point. Method should have a lot of words, when to strengthen the data ~ ~
struct node {int x, y;}
P[n],a[n];
int N,tot; Double Dis (node A,node b) {return hypot (A.X-B.X,A.Y-B.Y);} int multi (node P0,node p1,node p2) {return (p1.x-p0.
X) * (P2.Y-P0.Y)-(p2.x-p0.x) * (P1.Y-P0.Y);
} int cmp (node A,node b) {int x=multi (a,b,p[0]); if (x>0| | (X==0&&dis (a,p[0]) <dis (b,p[0])))
return 1;
return 0;
} int cmp1 (node A,node b) {if (a.x!=b.x) return a.x<b.x;
Return a.y<b.y;
} void Graham () {int k=0; for (int i=1;i<n;i++) if (p[i].y<p[k].y| | (p[i].y==p[k].y&&p[i].x<p[k].x))
K=i;
Swap (p[0],p[k]);
Sort (p+1,p+n,cmp);
TOT=2,A[0]=P[0],A[1]=P[1];
for (int i=2;i<n;i++) {while (Tot>1&&multi (P[i],a[tot-1],a[tot-2]) >=0) tot--;
A[tot++]=p[i];
} sort (A,A+TOT,CMP1);
for (int i=0;i<tot;i++) printf ("%d%d\n", a[i].x,a[i].y);
} int main () {int t;
scanf ("%d", &t);
while (t--) {scanf ("%d", &n); for (int i=0;i<n;i++) sCANF ("%d%d", &p[i].x,&p[i].y);
Graham ();
} return 0; }
0MS past, visual background than water.