Nyoj sprinkler (1) (simple greedy) and nyoj sprinkler greedy

Source: Internet
Author: User

Nyoj sprinkler (1) (simple greedy) and nyoj sprinkler greedy
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 Input
252 3.2 4 4.5 6 101 2 3 1 2 1.2 3 1.1 1 2
Sample output
25
Source
[Miao Dongdong] original
Uploaded

Miao Dongdong

The Code is as follows:

#include<stdio.h>#include<math.h> int main(){int t,n,i,j;double k,w,a[660];scanf("%d",&t);while(t--){scanf("%d",&n);for(i=0;i<n;i++)scanf("%lf",&a[i]);for(i=0;i<n;i++){for(j=i+1;j<n;j++){if(a[i]<a[j])k=a[i],a[i]=a[j],a[j]=k;}}w=20;int count=0;for(i=0;w>=0;i++){w-=2*sqrt(a[i]*a[i]-1);count++;}printf("%d\n",count);}return 0;}



An Automatic Sprinkler with a maximum distance of 20 meters. This sprinkler can spray flowers and plants in a variety of areas.

If there is no cover within 125 m², it's very easy. What is the circular area. 20 meters is the radius (r), S (area of the circle) = π r², π = 3.14
 
(One-dimensional equation) Water Sprinkler should be built in the center of a Circular Pool

Guarantee h =-(x-1) 2 + 2.25> 0

-0.5 <x <2.5

Based on the question 0 <= x <2.5,
So the pool radius must be at least MB before being sprayed out of the pool.

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.