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<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<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