Nyoj 6 sprinkler (1)

Source: Internet
Author: User

/*
Question:
Chinese Translation:
Question:
Solution:
Difficulties: Use a formula SQRT (A [I] * A [I]-1 ). He asks for the side length, so that the side length is sum, sum = SQRT (R * R-1) * 2, if not enough to continue adding a rectangle know enough.

Key points: fast release,
Problem solving person: lingnichong
Solution time:

Feeling: I have been writing it for a long time before I can understand what it means.
*/


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



#include<stdio.h>#include<stdlib.h>#include<string.h>#include<math.h>//#include<algorithm>//using namespace std;double a[660]={0};int cmp(const void *b,const void *a){return *(double *)a>*(double *)b? 1:-1;}int main(){int n,m,i,j;double sum;scanf("%d",&n);while(n--){memset(a,0,sizeof(a));scanf("%d",&m);for(i=0;i<m;i++)scanf("%lf",&a[i]);//sort(a,a+m);qsort(a,m,sizeof(a[0]),cmp);sum=0.0;for(i=0;i<m&&sum<10;i++)sum+=sqrt(a[i]*a[i]-1);printf("%d\n",i);}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.