您的位置:首页 > 产品设计 > UI/UE

POJ 1862 Stripies (priority_queue 优先队列)

2017-01-13 21:29 411 查看

做法:

全部放入队列,每次去两个大的进行

2 * sqrt(m1*m2 )

因为要使最终的结果最小,所以大的先进行开方,(是因为先进行合并的进行更多次开方)。

#include <iostream>
#include <cstdio>
#include <string.h>
#include <queue>
#include <cmath>
typedef long long int lli;
using namespace std;

int main(){
int t;
cin>>t;
priority_queue<double,vector<double>,less<double> > q;
int temp;
for(int i = 1;i <= t;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));
}
double ans = q.top();
printf("%.3f\n",ans);
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: