POJ 1328 Radar installation# greedy (coordinate geometry problem)

Source: Internet
Author: User
Tags cas radar

(~ ̄▽ ̄) ~*

#include <iostream>#include<cstdio>#include<algorithm>#include<cmath>using namespacestd;structnode{DoubleL,r; //Find the circle centered on the island with the radius of D and the left intersection of the x-axis, L, right intersection R//Radar is only located between L~r and the island is within radar coverage.}a[1005];intCMP (node A,node b) {returna.l<B.L;}intMain () {intn,d; DoubleRight ; intcas=0;  while(SCANF ("%d%d", &n,&d) &&n+d) {Cas++; BOOLflag=1;  for(intI=0; i<n;i++)        {            intx, y; scanf ("%d%d",&x,&y); A[I].L=X-SQRT (d*d*1.0-y*y*1.0); A[I].R=X+SQRT (d*d*1.0-y*y*1.0); intdis; if(y<0) dis=-y; Elsedis=y; if(dis>d) flag=0; }        if(!flag) printf ("Case %d: -1\n", Cas); Else        {            intans=1; Sort (A,a+n,cmp); Right=a[0].R;  for(intI=1; i<n;i++)            {                if(a[i].l>Right ) {ans++; Right=A[I].R; }                if(a[i].r<Right ) right=A[I].R; } printf ("Case %d:%d\n", Cas,ans); }    }    return 0;}

POJ 1328 Radar installation# greedy (coordinate geometry problem)

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.