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. javascript类式继承模式#4——共享原型

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...

  2. 剑指Offer - 九度1510 - 替换空格

    剑指Offer - 九度1510 - 替换空格2013-11-29 20:53 题目描述: 请实现一个函数,将一个字符串中的空格替换成“%20”.例如,当字符串为We Are Happy.则经过替换之 ...

  3. Object Pascal中文手册 经典教程

    Object Pascal 参考手册 (Ver 0.1)ezdelphi@hotmail.com OverviewOverview(概述)Using object pascal(使用 object p ...

  4. 【Multiply Strings】cpp

    题目: Given two numbers represented as strings, return multiplication of the numbers as a string. Note ...

  5. ADB push 和ADB pull命令

    adb push命令 :从电脑上传送文件到手机: adb pull命令 :从手机传送文件到电脑上      

  6. C++树的建立和遍历

    #include<iostream.h> typedef char TElemtype; typedef struct Btree { TElemtype data; struct Btr ...

  7. Python 3.x的编码问题

    Python 3的源码.py文件的默认编码方式为UTF-8(Python 2.x的默认编码格式为unicode). encode的作用,使我们看到的直观的字符转换成计算机内的字节形式. decode刚 ...

  8. PHP文件开头session_start()

    session_start(); 告诉服务器使用session.一般来说,php是不会主动使用session的. 不过可以设置php.ini中的session.auto_start=1来自动对每个请求 ...

  9. vue & lifecycle methods & this bug & ES6 Arrow function & this bind bug

    vue & lifecycle methods & this bug ES6 Arrow function & this bind bug bad fetchTableData ...

  10. 使用C#创建windows服务程序

    创建windows服务项目 一.创建服务 1.文件->新建->项目->windows桌面->windows服务,修改你要的项目名称.我这不改名,仍叫WindowsService ...