http://poj.org/problem?id=1328
First time: Starting from the first non-covered island on the left-->> failed because there is a y-coordinate. This factor cannot guarantee greed
Second time: Find two points to determine a circle----->>> It's long overdue to find that wrong is not universal
Find the point of the first y-coordinate >= (if not found) from the first non-covered point on the left to the common circle of the two points
If you can't do either of these two points of the public circle or no y>= point then do this circle right limit circle
Update the points covered
Stupid-->>.
Final strategy: Focus all on the x-axis and have an interval on each island as the center of the x-axis, so radar can cover the islands in this range.
So the left interval of all islands is divided into a radar with a sort interval overlap
A wrong way of thinking totally negated
On-line theft of a picture description
1#include <iostream>2#include <stdio.h>3#include <stdio.h>4#include <algorithm>5#include <math.h>6 using namespacestd;7 8 struct Island9 {Ten intx, y; One Doublelimit_l, Limit_r; A BOOLcover; - BOOL operator< (island a)Const - { the returnlimit_l < a.limit_l;//sort by left interval - } -}island[1024x768]; - intN, D; + - intSolve () + { A Doublelimit_l, Limit_r; at intCNT =1; - if(! Nreturn 0;//if N==0 - for(inti =0; i < N; i++) - { -island[i].limit_l = Island[i].x-sqrt (d*d-island[i].y*island[i].y); -Island[i].limit_r = island[i].x + sqrt (d*d-island[i].y*island[i].y); in } -Sort (island, island+n);//sort by left interval tolimit_l = island[0].limit_l;//and finally forgot to initialize and then hang up. +Limit_r = island[0].limit_r; - for(inti =1; i < N; i++) the { * //cnt++;//First Radar $ if(Island[i].limit_l >Limit_r)Panax Notoginseng { -cnt++; thelimit_l =island[i].limit_l; +Limit_r =Island[i].limit_r; A } the Else if(Island[i].limit_r <Limit_r) + { -Limit_r = island[i].limit_risland[i].x-sqrt (d*d island[i].y*island[i].y); $ } $ } - returnCNT; - } the intMain () - {WuyiFreopen ("In.txt","R", stdin); the BOOLFail =false; - intCase =0; Wu while(~SCANF ("%d%d", &n, &d)) - { About if(N = =0&& D = =0) Break; $GetChar ();//Blank Line -Fail =false;//Flag of Failure -case++; - for(inti =0; i < N; i++) A { +scanf"%d%d", &island[i].x, &island[i].y); the if(Island[i].y > D | | island[i].y <0) - { $Fail =true; the } the } the if(fail) printf ("Case %d:%d\n", Case,-1); the Elseprintf"Case %d:%d\n", case, solve ()); - } in return 0; the}
View Code
POJ 1328 Radar Installation