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. VSX-5 VSXMusic 编码听音乐

    给VS写个扩展来听音乐的说法,缘来已久,这两天做了个初版,使用豆瓣FM,先发出来. 插件现在只做了VS2013的,别的版本有待下一步支持. 现在暂时只有一个Adornment(就是那个有封面的),一个 ...

  2. php jsonp单引号转义

    php中jsonp输出时一般用下面的格式: callbackname('json string'); 如果中间的json string中含有单引号,这个输出就是有问题的,调用方一般是无法处理的,所以我 ...

  3. 最近做group assignment需要些加密的知識

    需求:A給B單向發的數據需要被加密,A和B都可以看到原文.加密后,就算傳輸的過程被竊取,也無法得知數據原文.A可以是任何客戶端. 解決:常用的MD5,sha1等常用的加密算法為單向不可逆,顯然不符合需 ...

  4. DesiredCapabilities的作用

    负责启动服务端时的参数设置,启动session的时候是必须提供的. Desired Capabilities本质上是key value的对象,它告诉appium server这样一些事情,比如: 本次 ...

  5. Tornado详解

    1.Tornado路由系统 1.1 Tornado程序示例 新建一个tornadodemo.py, import tornado.ioloop import tornado.web user_info ...

  6. 一个初学者的辛酸路程-基于Django写BBS项目

    前言 基于Django的学习 详情 登录界面 找个模板 http://v3.bootcss.com/examples/signin/ 右键,检查源码     函数 def login(request) ...

  7. 孤荷凌寒自学python那些事第一天

    孤荷凌寒自学python第一天 初识python (学习过程的完整录像分享链接在文末,手写笔记图片在文末) 一种编程语言,首先是它的语言的基本架构,python总体让人耳目一新: 今天其实只接触到了它 ...

  8. 稀疏矩阵相乘-Python版

                                          稀疏矩阵相乘-Python版 Given two sparse matrices A and B, return the r ...

  9. NYOJ 简单数据结构

    NYOJ 2 括号配对问题 栈的简单应用.可使用STL. #include <iostream> #include <cstdio> #include <cstring& ...

  10. C# 命名管道

    有些场合需要高效率,进行线程间通信,可以使用 C#命名管道.