[贪心]poj1862 Stripies

http://poj.org/problem?id=1862
简单题,每次取最大的两个做运算即可。

#include <iostream>
#include<algorithm>
#include<queue>
#include<cstdio>
#include<cmath>
#include<cstring>

using namespace std;
int n;
int main()
{
    int temp;
    scanf("%d",&n);
    priority_queue<double> q;
    for(int i = 0;i<n;i++)
    {
        scanf("%d",&temp);
        q.push(temp);
    }
    while(q.size() != 1)
    {
        double a = q.top();
        q.pop();
        double b = q.top();
        q.pop();
        q.push(2*sqrt(a*b));
    }
    printf("%.3f\n",q.top());
    return 0;
}

你可能感兴趣的:([贪心]poj1862 Stripies)