Va -- 10382 Watering Grass + greedy
Question:
A rectangular lawn with a length of W and a Center Coordinate and radius of n sprinklers are given. You need at least a few sprinklers to cover the lawn.
Ideas:
At the beginning, I felt that I could figure out the range that each nozzle could cover, and then it turned into the previous range coverage problem. I took a look at the example below, it is wrong to think like this, because the arc on the edge of the nozzle may not cover the lawn completely, so other sprinklers must be covered in those places, in this way, we cannot directly use the range merge. I thought about it later. In fact, the valid area covered by each nozzle is a rectangle. We only need to find the valid area covered by each nozzle (that is, the part of the rectangle completely contained in the circle, with simple geometric knowledge, you can get it), and it becomes a range coverage problem! Note: If the radius of a nozzle is not half the width of the rectangle, the valid area covered by the nozzle is 0 (equivalent to the inner circle of the rectangle ), we can ignore these sprinklers.
The Code is as follows:
#include
#include
#include
#include
#includeusing namespace std;typedef struct{ double x,y;}P;P p[11000];int cmp(P p1,P p2){ return p1.x
max1) max1=p[i].y; i++; } if(max1==0) break; cnt++; left=max1; if(left>=len) { flag=1; break; } } if(flag) printf("%d\n",cnt); else printf("-1\n"); } return 0;}