不知道为什么这个简单的贪心还是出错

poj1862

不知道错哪的代码:

#include<iostream>
#include<algorithm>
#include<cmath>
#include<cstring>
#define Max 102
using namespace std;
int n;
double weight[Max];
double sum=0;
bool cmp(double a,double b){
return a>b;
}
int main()
{
//freopen("poj1862.txt","r",stdin);
while(scanf("%d",&n)!=EOF){


memset(weight,0,sizeof(weight));
for(int i=0;i<n;i++)
{
scanf("%lf",&weight[i]);
}
sort(weight,weight+n,cmp);
while(weight[1]!=-1)
{
weight[0] = 2*sqrt(weight[0]*weight[1]);
weight[1]=-1.0;
sort(weight,weight+n,cmp);
}
printf("%.3lf\n",weight[0]);
}
return 0;
}
 

猜你喜欢

转载自blog.csdn.net/qq_26939031/article/details/80170055
今日推荐