Stripies
Time Limit: 1000MS   Memory Limit: 30000K
Total Submissions: 18198   Accepted: 8175

Description

Our chemical biologists have invented a new very useful form of life called stripies (in fact, they were first called in Russian - polosatiki, but the scientists had to invent an English name to apply for an international patent). The stripies are transparent amorphous amebiform creatures that live in flat colonies in a jelly-like nutrient medium. Most of the time the stripies are moving. When two of them collide a new stripie appears instead of them. Long observations made by our scientists enabled them to establish that the weight of the new stripie isn't equal to the sum of weights of two disappeared stripies that collided; nevertheless, they soon learned that when two stripies of weights m1 and m2 collide the weight of resulting stripie equals to 2*sqrt(m1*m2). Our chemical biologists are very anxious to know to what limits can decrease the total weight of a given colony of stripies. 
You are to write a program that will help them to answer this question. You may assume that 3 or more stipies never collide together. 

Input

The first line of the input contains one integer N (1 <= N <= 100) - the number of stripies in a colony. Each of next N lines contains one integer ranging from 1 to 10000 - the weight of the corresponding stripie.

Output

The output must contain one line with the minimal possible total weight of colony with the accuracy of three decimal digits after the point.

Sample Input

3
72
30
50

Sample Output

120.000

Source

Northeastern Europe 2001, Northern Subregion
 
 
【题意】:给出n个物体,分别给出每个的质量,并且两个物体(假设质量分别为m1,m2)相撞的时候变成一个物体,质量为2*sqrt(m1*m2),并且只会出现两个两个物品碰撞的情况,问最终能得到的物体的最小质量是多少。

【分析】:类似于哈弗曼树的方法,每次选举两个当前最大的数值进行运算,直到剩下一个物品。使用优先队列处理比较方便。

【代码】:

#include<iostream>
#include<stdio.h>
#include<vector>
#include<queue>
#include<cmath>
using namespace std; #define LL long long
using namespace std;
const int N = +;
int n;
double L;
double a,b;
priority_queue<double> q;
int main()
{
cin>>n; for(int i=;i<n;i++)
{
cin>>L;
q.push(L);
}
while(q.size()>)
{
a=q.top();q.pop(); b=q.top();q.pop(); q.push(*sqrt(a*b));
}
printf("%.3f\n",q.top()); return ;
}

POJ 1862 Stripies【哈夫曼/贪心/优先队列】的更多相关文章

  1. poj3253 Fence Repair【哈夫曼树+优先队列】

    Description Farmer John wants to repair a small length of the fence around the pasture. He measures ...

  2. poj 1862 Stripies/优先队列

    原题链接:http://poj.org/problem?id=1862 简单题,贪心+优先队列主要练习一下stl大根堆 写了几种实现方式写成类的形式还是要慢一些... 手打的heap: 1: #inc ...

  3. Fence Repair POJ - 3253 哈夫曼思想 优先队列

    题意:给出一段无限长的棍子,切一刀需要的代价是棍子的总长,例如21切一刀 变成什么长度 都是代价21 列如7切成5 和2 也是代价7题解:可以利用霍夫曼编码的思想 短的棍子就放在底层 长的尽量切少一次 ...

  4. poj 3253 哈夫曼贪心

    http://poj.org/problem?id=3253 题意: FJ需要修补牧场的围栏,他需要 N 块长度为 Li 的木头(N planks of woods).开始时,FJ只有一块无限长的木板 ...

  5. [POJ 1521]--Entropy(哈夫曼树)

    题目链接:http://poj.org/problem?id=1521 Entropy Time Limit: 1000MS    Memory Limit: 10000K Description A ...

  6. 【PTA 天梯赛训练】修理牧场(哈夫曼树+优先队列)

    农夫要修理牧场的一段栅栏,他测量了栅栏,发现需要N块木头,每块木头长度为整数L​i​​个长度单位,于是他购买了一条很长的.能锯成N块的木头,即该木头的长度是L​i​​的总和. 但是农夫自己没有锯子,请 ...

  7. POJ 1862 Stripies 贪心+优先队列

    http://poj.org/problem?id=1862 题目大意: 有一种生物能两两合并,合并之前的重量分别为m1和m2,合并之后变为2*sqrt(m1*m2),现在给定n个这样的生物,求合并成 ...

  8. POJ 1862 Stripies (哈夫曼树)

    Stripies Time Limit: 1000MS   Memory Limit: 30000K Total Submissions: 10263   Accepted: 4971 Descrip ...

  9. poj 3253 Fence Repair (哈夫曼树 优先队列)

    题目:http://poj.org/problem?id=3253 没用long long wrong 了一次 #include <iostream> #include<cstdio ...

随机推荐

  1. Ajax异步与JavaScript的一些初浅认识

    向服务器请求数据的技术 有以下五种常用技术用于向服务器请求数据 XMLHttpRequest(XHR) Dynamic script tag insertion(动态脚本标签插入) iframes C ...

  2. LCS+LIS

    #include<iostream> #include<string> using namespace std; string a,b; ][]; int main() { w ...

  3. Python 3基础教程12-常见的错误

    本文来介绍几种常见的错误,任何人在刚开始接触一个新的语言,即使照着代码抄写,也可能会犯错误,这里我们就介绍几种常见的错误,看看你是否遇到过. 1. NameError: name 'xxx' is n ...

  4. Springboot 启动问题

    每次以debug方式启动springboot之后都会在SilentExitExceptionHandler类中的throw new SilentExitException() 解决办法 :window ...

  5. StaticBox布局管理器

    wx.StaticBoxSizer构造方法如下: wx.StaticBoxSizer(box,orient = HORIZONTAL) box 是静态框对象,orient参数是布局方向  wx.HOR ...

  6. OpenStack-Ironic裸金属简介

    一,Ironic简述 简而言之,OpenStack Ironic就是一个进行裸机部署安装的项目.    所谓裸机,就是指没有配置操作系统的计算机.从裸机到应用还需要进行以下操作:  (1)硬盘RAID ...

  7. 洛谷P1101单词方阵

    题目描述 给一n×n的字母方阵,内可能蕴含多个“yizhong”单词.单词在方阵中是沿着同一方向连续摆放的. 摆放可沿着 8个方向的任一方向,同一单词摆放时不再改变方向,单词与单词之间可以交叉,因此有 ...

  8. Android数据储存之SharedPreferences总结

    写在前面:本文是我参考李刚老师的<疯狂Android讲义>以及API所写的读书笔记,在此表示感谢,本人小白,如有错误敬请指教. SharedPreferences的使用背景: 有时候,应用 ...

  9. Alpha 冲刺

    队名:我头发呢队 组长博客 作业博客 杰(组长) 过去两天完成了哪些任务 查阅Python爬取音源的资料,如 Python3爬虫抓取网易云音乐热评实战 Python爬取高品质QQ音乐(2) 如何爬网易 ...

  10. 微信公众号开发java框架:wx4j(入门篇)

    导航 入门 http://www.cnblogs.com/2333/p/6617819.html WxServlet介绍 MaterialUtils 素材工具类使用说明 http://www.cnbl ...