poj 1862 Stripies

题意:

有一种名为stripie的生物,每次当两个质量为m1 和 m2的这种生物相遇之后,它们会合体成为一个个体,这个个体的质量变为2 * sqrt(m1 * m2)。给出n个生物的质量,问他们相遇之后最后剩下一个个体时,最小的质量是多少,保证不会有超过2个这种生物碰到一起的情况。

思路:

哈夫曼树变种,优先队列解决。

代码:

#include <stdio.h>
#include <string.h>
#include <queue>
#include <vector>
#include <math.h>
using namespace std;
 
priority_queue<double,vector<double>,less<double> > pq;
 
int main()
{
	int n;
	
	while (scanf("%d",&n) != EOF)
	{
		while (!pq.empty()) pq.pop();
		
		for (int i = 0;i < n;i++)
		{
			double x;
			scanf("%lf",&x);
			pq.push(x);
		}
		
		while (pq.size() >= 2)
		{
			double x = pq.top();pq.pop();
			double y = pq.top();pq.pop();
			
			double tmp = 2 * sqrt(x * y);
			
			pq.push(tmp);
		}
		
		printf("%.3f\n",pq.top());
	}
	
	return 0;
}

 

转载于:https://www.cnblogs.com/kickit/p/8808083.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值