Water spraying device (i.)

Source: Internet
Author: User

Time limit:MS | Memory limit:65535 KB Difficulty:3
Describe
The
existing lawn, 20 meters wide, 2 meters in width, to place the radius of Ri on the horizontal centerline of the sprinkler device, the effect of each water spray device will be the center of the radius of the real Ri (0<ri<15) of the circle is moist, there is sufficient water spray device I (1<i< 600), and must be able to wet all the lawn, what you have to do is: choose as little as possible water spray device, the whole lawn moist.
Input
The
first line m indicates that there is a m group of test data
The first line of each set of test data has an integer number N,n represents a total of n water jets, followed by a row of n real Ri,ri that indicate the radius of the circle that the water spray device can cover.
Output
number of devices used in the 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
C + + Excellent code
#include <iostream>
#include <vector>
#include <functional>
#include <algorithm>
#include <cmath>
using namespace Std;
Double Length (double r,double b)
{
Return 2*sqrt (R*R-B*B/4);
}
int main ()
{
const double l=20,w=2;
int n;
cin>>n;
while (n--)
{
int m;
cin>>m;
Double R;
Vector<double> Rs;
while (m--)
{
cin>>r;
Rs.push_back (R);
}
Sort (Rs.begin (), Rs.end (),greater<double> ());
Double sum=0;
int i;
For (I=0;i!=rs.size (); i++)
{
if (sum>l) break;
Sum+=length (RS[I],W);
}
cout<<i<<endl;
}
}




v1.0 C
#include <stdio.h>
#include <math.h>
#define SPRAYNUM 600
void QuickSort (double arr[], int left, int. right);
int main (void)
{
int m;
int n;
int k;
Int J;
Double ri[spraynum]={0};
scanf ("%d", &m);
GetChar ();


for (j = 0; j < m; ++j) {
scanf ("%d", &n);
GetChar ();

for (k = 0; k < n; ++k) {
scanf ("%lf", &ri[k]);
}

QuickSort (ri,0,n-1);
int sum=1;

Double tmpsqrt=sqrt (POW (ri[n-1],2)-1)-10;


for (k =n-2; k >=0; k--) {
if (tmpsqrt >= 0) {

printf ("%d\n", sum);
Break
}
else {
Tmpsqrt + = sqrt (Pow (ri[k],2)-1);
++sum;

}


}


}


return 0;
}

void QuickSort (double arr[], int left, int. right) {
int i=left;
int j=right;

Double pivot = arr[(left + right)/2];
Double tmp;
while (I <= j) {
while (Arr[i] < pivot) {
i++;
}

while (Arr[j] > Pivot) {
j--;
}

if (i<=j) {
Tmp=arr[i];
ARR[I]=ARR[J];
arr[j]=tmp;
i++;
j--;
}
}
if (Left < J) QuickSort (arr, left, J);
if (I < right) QuickSort (arr, I, right);
}




v0.1 C
#include <stdio.h>
#include <math.h>

#define SPRAYNUM 600
void QuickSort (double arr[], int left, int. right);
int main (void)
{
int m;
int n;
int k;
Int J;
Double ri[spraynum]={0};
scanf ("%d", &m);
GetChar ();


for (j = 0; j < m; ++j) {
scanf ("%d", &n);
GetChar ();

for (k = 0; k < n; ++k) {
scanf ("%lf", &ri[k]);
}
/*for (k = 0; k < n; ++k) {
printf ("%.2lf", Ri[k]);
}*/
printf ("\ n");
QuickSort (ri,0,n-1);
int sum=1;

Double tmpsqrt=sqrt (POW (ri[n-1],2)-1)-10;
printf ("line:%d,tmpsqrt:%lf\n", __line__, TMPSQRT);

for (k =n-2; k >=0; k--) {
if (tmpsqrt >= 0) {
printf ("tmpsqrt:%lf\n", tmpsqrt);
printf ("%d\n", sum);
Break
}
else {
Tmpsqrt + = sqrt (Pow (ri[k],2)-1);
++sum;
printf ("%d\n", sum);
}


}


}


return 0;
}

void QuickSort (double arr[], int left, int. right) {
int i=left;
int j=right;

Double pivot = arr[(left + right)/2];
Double tmp;
while (I <= j) {
while (Arr[i] < pivot) {
i++;
}

while (Arr[j] > Pivot) {
j--;
}

if (i<=j) {
Tmp=arr[i];
ARR[I]=ARR[J];
arr[j]=tmp;
i++;
j--;
}
}
if (Left < J) QuickSort (arr, left, J);
if (I < right) QuickSort (arr, I, right);
}



Water spraying device (i.)

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.