标签:
2 5 2 3.2 4 4.5 6 10 1 2 3 1 2 1.2 3 1.1 1 2
2 5
//C++ 优秀代码
#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);
}
标签:
原文地址:http://www.cnblogs.com/guxuanqing/p/5576438.html