POJ 1328 Radar Installation

Source: Internet
Author: User
Tags radar

Radar InstallationTime limit:1000msMemory limit:10000kTotal submissions:51377accepted:11527


Idea: Each island has an interval on the x-axis that can be covered by radar, X1 to a covered left end, X2 to the right end of the overlay, and x1,x2 about the island's X symmetry.
First sort the island by X, then greedy.

The interval of the first island len[I].right with the subsequent islands and the interval len[K].left is larger than the assumption that the former is greater than the inverse then the interval is updated to the latter's interval range at this time ans+1 (note assuming that there are islands of the interval

Len [k].right< the former interval len[i].right will update the interval to len[K].right) in the continuation;

In short, let the radar in the current situation to meet the premise of as far as possible to the right.



#include <iostream> #include <cstdio> #include <cmath> #include <algorithm> #include <    Stdlib.h>using namespace std;struct class{double x; Double y;}    Zb[1005];struct std{double S; Double e;} LEN[1005];d ouble r;int ans,n;bool cmp (Class A,class b) {return a.x<b.x;} void Worklen ()//The corresponding area of each island that can be put into the radar is computed {for (int i=0;i<n;i++) {/*cout<<len[i].s<< "" <<l        en[i].e<<endl;*/len[i].s=zb[i].x-sqrt (r*r-(ZB[I].Y*ZB[I].Y));    Len[i].e=zb[i].x+sqrt (r*r-(ZB[I].Y*ZB[I].Y));    }}void work () {int J;          int l=0; for (j=1;j<n;j++) {if (LEN[J].E&LT;LEN[L].E) {l=j;//when there is                        The area of the J Islands radar is more than the hour of the L islands attention to the minimum as a comparison of the standard} else if (LEN[L].E&LT;LEN[J].S) {                        ans++;                     L=j; }} return;    int main () {int i,flag,t=1; while (cin>>n>>r,n| |        R) {flag=0;        Ans=1;            for (i=0;i<n;i++) cin>>zb[i].x>>zb[i].y;                   for (i=0;i<n;i++) if (Fabs (ZB[I].Y) >r) {flag=1;                if (flag) {cout<< "case" <<t<< ":" << "1" <<endl;            t++;            } else {sort (zb,zb+n,cmp);            /*for (i=0;i<n;i++) cout<<zb[i].x<< "" <<zb[i].y<<endl;*/Worklen ();            Work ();            cout<< "Case" <<t<< ":" <<ans<<endl;        t++; }} return 0;}


POJ 1328 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.