POJ 1862 Stripies

每次合并最大的两个,优先级队列维护一下。

输出的时候%.3lf G++会WA,C++能AC,改成%.3f,都能AC。

#include<cstdio>
#include<cstring>
#include<cmath>
#include<queue>
#include<algorithm>
using namespace std;

int n,s;
priority_queue<double>Q;

int main()
{
    while(~scanf("%d",&n))
    {
        while(!Q.empty())Q.pop();
        for(int i=1; i<=n; i++)
        {
            double x;
            scanf("%lf",&x);
            Q.push(x);
        }

        s=n;
        if(s==1)printf("%.3f\n",Q.top());
        else
        {
            while(1)
            {
                double num1=Q.top();
                Q.pop();
                s--;
                double num2=Q.top();
                Q.pop();
                s--;
                Q.push(2*sqrt(num1*num2));
                s++;
                if(s==1)
                {
                    printf("%.3f\n",Q.top());
                    break;
                }
            }
        }
    }
    return 0;
}

 

posted @ 2016-03-24 09:00  Fighting_Heart  阅读(135)  评论(0编辑  收藏  举报