To the effect:
a sequence
xi
requires two operations to be performed, and two
Calculate
and put back
Analysis:
The greedy strategy is either forward or reverse, simply prove the three relationships:
Easy to get forward processing to get maximum, reverse order minimum
Implementation:
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<string>
#include<cmath>
using namespace std;
#define pb push_back
#define inf (1e9+10)
#define mem(s,t) memset(s,t,sizeof s)
typedef pair<int,int> pii;
typedef long long ll;
const int MAXN =1e4+10;
int main() {
int n;
cin>>n;
double a[MAXN];
for(int i=1;i<=n;i++){
cin>>a[i];
}
sort(a+1,a+n+1);
for(int i=n-1;i;i--){
a[i]=2.0*sqrt(1.0*a[i]*a[i+1]);
}
printf("%.3f\n",a[1]);
return 0;
}