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

xiaoxiao2021-02-28  46

poj1862

不知道错哪的代码:

#include<iostream>#include<algorithm>#include<cmath>#include<cstring>#define Max 102using 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;} 

转载请注明原文地址: https://www.6miu.com/read-2613352.html

最新回复(0)