本题是典型的贪心算法:
假设有3个数字 a,b,c

想要S1 代码如下: [cpp]
#include
#include
#include
using namespace std;
#define MAX 1000
void bubble_sort(int s[],int len)
{
bool flag=true;
for(int ii=len-1;ii>0&&flag;ii--)
{
flag=false;
for(int jj=0;jj
if(s[jj]>s[jj+1]) //冒泡法,小的数字冒到上面
{
int temp= s[jj];
s[jj]=s[jj+1];
s[jj+1] = temp;
flag=true; //如果有一次交换,说明还没有排好;如果本次没有进行调整,说明已经排序完成
}
}
}
}
int main()
{
int n;
int stripy[MAX];
memset(stripy,0,MAX*sizeof(int));
cout.precision(3);
cout.setf(ios::fixed);
while (cin>>n)
{
for (int ii=0;ii
cin>>stripy[ii];
}
bubble_sort(stripy,n);
double newdata=stripy[n-1];
for(int ii=n-2;ii>=0;ii--)
{
newdata = 2*sqrt(newdata*stripy[ii]);
}
cout<
return 0;
}