tanxin -- Lti - Stripies
代码如下:
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
#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; }