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

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

题意:即给你一定的生物,他们会有一定的重量,如果他们相互碰撞,    那么根据题目给的那个公式2*sqrt(m1*m2) ,质量会减少。

这个公式表示的是两个物品质量分别为m1和m2,而他们碰撞后的总质量会减少为2*sqrt(m1*m2)

给你一定的这样的生物及它们的质量,要你求它们经过碰撞后的最小总质量。

#include<iostream>
#include<cstdio>
#include<cstring>
#include<queue>
#include<cmath>
#include<algorithm> using namespace std; int n; int main(){ //freopen("input.txt","r",stdin); priority_queue<double> q;
while(~scanf("%d",&n)){
while(!q.empty())
q.pop();
double x,a,b;
for(int i=;i<n;i++){
scanf("%lf",&x);
q.push(x);
}
while(q.size()>){
a=q.top(); q.pop();
b=q.top(); q.pop();
x=*sqrt(a*b);
q.push(x);
}
printf("%.3f\n",q.top());
}
return ;
}

其实就是贪心的思想:

#include<iostream>
#include<cstdio>
#include<cstring>
#include<queue>
#include<cstdlib>
#include<cmath>
#include<algorithm> using namespace std; int n;
double num[]; int cmp(double a,double b){
return a>b;
} int main(){ //freopen("input.txt","r",stdin); while(~scanf("%d",&n)){
for(int i=;i<n;i++)
scanf("%lf",&num[i]);
sort(num,num+n,cmp);
double ans=num[];
for(int i=;i<n;i++) //ans始终为最大的,因为2*sqrt(a*b),a,b都是最大的,所以ans使最大的
ans=*sqrt(ans*num[i]);
printf("%.3f\n",ans);
}
return ;
}

POJ 1862 Stripies (哈夫曼树)的更多相关文章

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

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

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

    题目地址:POJ 3253 哈夫曼树的结构就是一个二叉树,每个父节点都是两个子节点的和. 这个题就是能够从子节点向根节点推. 每次选择两个最小的进行合并.将合并后的值继续加进优先队列中.直至还剩下一个 ...

  3. POJ 3253 Fence Repair(优先队列,哈夫曼树,模拟)

    题目 //做哈夫曼树时,可以用优先队列(误?) //这道题教我们优先队列的一个用法:取前n个数(最大的或者最小的) //哈夫曼树 //64位 //超时->优先队列,,,, //这道题的优先队列用 ...

  4. Poj 3253 Fence Repair(哈夫曼树)

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

  5. POJ 3253 Fence Repair(哈夫曼树)

    Fence Repair Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 26167   Accepted: 8459 Des ...

  6. 哈夫曼树---POJ3253

    http://poj.org/problem?id=3253 这就是 最典型的哈夫曼树的题型,我们就根据这道题学习一下哈夫曼树 这是最开始我们把21据下来之后我们据下8,然后再据下5得到34,可以看出 ...

  7. BZOJ 3253 Fence Repair 哈夫曼树 水题

    http://poj.org/problem?id=3253 这道题约等于合并果子,但是通过这道题能够看出来哈夫曼树是什么了. #include<cstdio> #include<c ...

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

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

  9. (哈夫曼树)HuffmanTree的java实现

    参考自:http://blog.csdn.net/jdhanhua/article/details/6621026 哈夫曼树 哈夫曼树(霍夫曼树)又称为最优树. 1.路径和路径长度在一棵树中,从一个结 ...

  10. 数据结构之C语言实现哈夫曼树

    1.基本概念 a.路径和路径长度 若在一棵树中存在着一个结点序列 k1,k2,……,kj, 使得 ki是ki+1 的双亲(1<=i<j),则称此结点序列是从 k1 到 kj 的路径. 从 ...

随机推荐

  1. Eclipse里选一个变量后,这个类里的该变量不变色了

    使用“Alt+Shift+O”对该提示功能的开/关切换

  2. curl_setopt — 设置 cURL 传输选项

    curl_setopt (PHP 4 >= 4.0.2, PHP 5, PHP 7) curl_setopt — 设置 cURL 传输选项 bool curl_setopt ( resource ...

  3. Git 常用命令 思维导图(转)

    Git 是一个很强大的分布式版本控制系统.它不但适用于管理大型开源软件的源代码,管理私人的文档和源代码也有很多优势. 本来想着只把最有用.最常用的 Git 命令记下来,但是总觉得这个也挺有用.那个也用 ...

  4. Office 超级录屏如何旋转视频90度之后保存

    打开视频转换专家   添加视频后点击编辑,然后在旋转的地方设置旋转,应用   输出可以正常播放  

  5. Word批量调整插入图片大小

    做标书,word中需要插入大量图片,实为一些证书.文件的扫描文件.但插入后,大小不是想要的,太小了,打印出来看不清.需要调整,需要批量调整. 这是一个不错的方法: 选中第一张图片,按页面调整大小到适合 ...

  6. Spring Boot中Starter是什么

    比如我们要在Spring Boot中引入Web MVC的支持时,我们通常会引入这个模块spring-boot-starter-web,而这个模块如果解压包出来会发现里面什么都没有,只定义了一些POM依 ...

  7. angular5中使用jsonp请求页面

    说多了,都是眼泪,折腾了很久,各种百度,查到的例子,全都报错,可能是因为我的angular的版本太高,向下都不兼容? 我的angular版本为最新的5.2.11: 下面是正确的jsonp请求的方法 1 ...

  8. phpMyadmin安装极简教程[下载,解压,登录]

    1.下载一个压缩包,例如: 2. 解压到web根目录并重命名为phpmyadmin 3.在浏览器输入http://localhost/phpmyadmin就可以看到登陆界面了,登陆之后,数据库,表的增 ...

  9. Jenkins知识地图

    转自:http://blog.csdn.net/feiniao1221/article/details/10259449 这篇文章大概写于三个月前,当时写了个大纲列表,但是在CSDN上传资源实在不方便 ...

  10. 创新大师Steve Blank: 你真的知道什么是真正的精益创业吗?

    编者注:本文来自被誉为当代创新大师的Steve Blank的博客. 中文版由天地会珠海分舵编译. 全文从当今非常多人对精益创业的误解作为一个切入点,深入的分析了为什么人们这么easy就对精益创业产生误 ...