Sprinkler (1)

Source: Internet
Author: User

Sprinkler (1) Time Limit: 3000 MS | memory limit: 65535 kb difficulty: 3
Description
There is a lawn with a length of 20 meters and a width of 2 meters. A sprinkler with a radius of RI should be placed on the horizontal center, the effect of each sprinkler will make the circle with its center radius as the real number Ri (0 <RI <15) moist, there are plenty of sprinkler I (1 <I <600), and you will surely be able to wet all the lawns. What you need to do is: select as few sprinkler as possible, wet all the lawns.
Input
The first line M indicates that there are M groups of test data
The first line of each set of test data has an integer N, N indicates a total of N sprinkler devices, and the subsequent line has n real number Ri, RI indicates the radius of the circle covered by the sprinkler.
Output
Number of devices used for output
Sample sample input
252 3.2 4 4.5 6 101 2 1 2 1.2 3 1.1 1 2
Sample output
2

5

Understanding of the details: N indicates a total of N sprinkler devices. This sentence means that there is a corresponding device for each radius R, there are n devices, of course, corresponding to n r; at first it was understood that we can always wet the lawn with the largest radius, and we can find that each device can only be used once. the following code and comments of the greedy method are provided;

#include 
      
        # include 
       
         // contains the rapidly sorted header file # include 
        
          // mathematical function header file double length (double r) // convert R to a valid value {return 2 * SQRT (double) (R * r-1 ));} int COM (const void * a, const void * B) // The Quick Sort comparison function {return (* (double *) B-* (double *) a> 0? 1:-1); // sort from big to small} int main () {int m, n, I, j = 0; // J counts the number of devices that meet> 1. Double R [1020], temp, sum = 0.0; // stores the scanf ("% d ", & M); While (M --) {scanf ("% d", & N); for (I = 0, j = 0; I 
         
           1) // discard devices less than or equal to 1 in radius R [J ++] = length (temp);} qsort (R, J, sizeof (R [0]), com ); // for (I = 0; I 
          
            = 20) // If sum is greater than or equal to 20, it indicates that break has been wet ;} printf ("% d \ n", I + 1); // Add 1 to the output, corresponding to the relationship with I, if I = 0 is to exit the loop, the task can be completed by one device. The relationship between the number of devices and I is displayed.} return 0;} 
          
         
        
       
      


sprinkler (1)

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.