Va -- 10382 Watering Grass + greedy

Source: Internet
Author: User

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




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.