题目地址:http://poj.org/problem?id=1862
思路:每次选最大的2个值乘
AC代码:
错误代码:
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <queue>
#include <stack>
#include <map>
#include <cstring>
#include <climits>
#include <cmath>
#include <cctype>
const int inf = 0x3f3f3f3f;//1061109567
typedef long long LL;
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
using namespace std;
struct node
{
double value;
bool operator < (const node &a) const
{
return value < a.value;//最大值优先
}
};
int main()
{
int n;
while(scanf("%d",&n) != EOF)
{
node a;
priority_queue<node> pq;
for(int i=0; i<n; i++)
{
double b;
scanf("%lf",&b);
a.value = b;
pq.push(a);
}
while(!pq.empty())
{
node b;
a = pq.top();
pq.pop();
if(pq.empty())
break;
b = pq.top();
pq.pop();
node c;
c.value = 2 * sqrt(a.value*b.value);
pq.push(c);
}
printf("%.3lf\n",a.value);
}
return 0;
}