P1325 Radar Installation

Source: Internet
Author: User
Tags radar

Transmission DoorIdeas:

Take the greedy thought.

Consider each island as a center, with the radar range D as the radius, to find the x-axis of the left and right two intersections, the two intersections sandwiched between the need to place a radar, so that the problem is converted to an interval to pick points. When enumerating islands, record the location of the last radar before LAS, if the island is within the range of the radar, skip it, otherwise, place a radar at the right end of the area where the island is located.

  For the code to look good, I hit a huge structure.

Main function Section:

intMain () {n=T.RESD ();d =T.read ();  for(LL i=1; i<=n;i++) {t[i].x=t.read (), t[i].y=T.read (); T[I].L=t.deal_l (T[I].X,T[I].Y);//calculates the left end of the intervalT[i].r=t.deal_r (T[I].X,T[I].Y);//calculates the right endpoint of the interval} sort (T+1, t+n+1, CMP);//Sort by interval right endpointlas=t[1].r;ans++;//Place the first radar, record the location of Las     for(LL i=2; i<=n;i++) {dis=t.dist (T[i].x,t[i].y,las,0);//calculates the distance between the island and the last radar placed before it        if(Dis<=d)Continue;Elselas=t[i].r,ans++;//if not within the radar range, place a radar at the right end of the interval and update the LAS. } printf ("%lld\n", ans); return 0; }
Full code:
#include <iostream>#include<cstdio>#include<algorithm>#include<cmath>#include<cstring>#include<string>#include<cstdlib>#include<stack>#include<vector>#include<queue>#include<deque>#include<map>#include<Set>using namespacestd;#defineMax (a) (a) > (b)? ( A):(B))#defineMin (a) < (b) ( A):(B))#defineMAXN 2001typedefLong LongLL; LL N,ans;DoubleD,las,dis;structhh{DoubleX,y,l,r;BOOLBo; InlineDoubleRead () {DoubleLS;SCANF ("%LF", &ls);returnls; } inline ll resd () {ll xs=0, kr=1;Charls; LS=GetChar ();  while(!isdigit (LS)) {            if(! (ls^ $)) KR=-1; LS=GetChar (); }         while(IsDigit (LS)) {xs= (xs<<1) + (xs<<3) + (ls^ -); LS=GetChar (); }        returnxs*KR; } InlineDoubledeal_l (DoubleADoubleb) {returnA-SQRT (d*d-b*b); } InlineDoubleDeal_r (DoubleADoubleb) {returnA+SQRT (d*d-b*b); } InlineDoubleDistDoubleA1,DoubleB1,DoubleA2,DoubleB2) {        returnsqrt ((A1-A2) * (A1-A2) + (B1-B2) * (b1-B2)); }}t[maxn],t;inlineBOOLcmpConstHh&a,Consthh&b) {    returna.r<B.R;}intMain () {n=T.RESD ();d =T.read ();  for(LL i=1; i<=n;i++) {t[i].x=t.read (), t[i].y=T.read (); T[I].L=t.deal_l (T[I].X,T[I].Y); T[I].R=T.deal_r (T[I].X,T[I].Y); } sort (T+1, t+n+1, CMP); Las=t[1].r;ans++;  for(LL i=2; i<=n;i++) {dis=t.dist (T[i].x,t[i].y,las,0); if(Dis<=d)Continue; Elselas=t[i].r,ans++; } printf ("%lld\n", ans);return 0;}

P1325 Radar Installation

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.