NYOJ-78 Circle pool, convex hull bare template!

Source: Internet
Author: User

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.



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.