tanxin -- Lti - Stripies

 

代码如下:

#include <iostream>
#include<stdio.h>
#include<algorithm>
#include<math.h>

using namespace std;

int n;
double a[102];
double ans;
int cnt=1;

bool cmp(int a,int b){
    return a>b;
}

double suan(double x,double y){
    double temp;
    temp=2*sqrt(x*y);
    cnt++;                // 数组下标
    y=a[cnt];
    if(cnt < n){ temp=suan(temp,y);}
    else{ return temp;}
    return temp;
}

int main()
{
    scanf("%d",&n);
    for(int i = 0 ; i < n ; i++){ scanf("%lf",&a[i]);}

    if(n==1){ans=(double)a[0];printf("%.3lf\n",ans);return 0;}
    sort(a,a+n,cmp);
    ans = suan(a[0],a[1]);
    printf("%.3lf",ans);

    return 0;
}
View Code

 

posted @ 2018-12-15 21:34  烂科人  阅读(96)  评论(0编辑  收藏  举报