Stripies
Time Limit: 1000MS   Memory Limit: 30000K
Total Submissions: 21506   Accepted: 9478

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

贪心和优先队列,先选择最大的两个数合并,然后加入队列,可以用priority_queue(),默认为最大堆。
C++代码(只能用C++编辑器过,G++却会WA)
#include<iostream>
#include<queue>
#include<algorithm>
#include<cstdio>
#include<cmath>
using namespace std;
int main(){
priority_queue<double> pq;
int N;
scanf("%d",&N);
double m;
int t = N;
while(t--){
scanf("%lf",&m);
pq.push(m);
}
int k = N - ;
double a,b;
while(k--){
a = pq.top();
pq.pop();
b = pq.top();
pq.pop();
pq.push( * sqrt(a*b));
}
printf("%.3lf\n",pq.top());
pq.pop();
return ;
}
#include<iostream>
#include<queue>
#include<algorithm>
#include<cstdio>
#include<cmath>
using namespace std;
int main(){
priority_queue<double> pq;
int N;
scanf("%d",&N);
double m;
int t = N;
while(t--){
scanf("%lf",&m);
pq.push(m);
}
double a,b,tmp;
while(!pq.empty()){
a = pq.top();
pq.pop();
if(pq.empty()){
printf("%.3lf\n",a);
break; //要加break
}
b = pq.top();
pq.pop();
tmp = * sqrt(a*b);
pq.push(tmp);
}
return ;
}

(贪心和优先队列) POJ1862 Stripies的更多相关文章

  1. Luogu 1090 合并果子(贪心,优先队列,STL运用)

    Luogu 1090 合并果子(贪心,优先队列,STL运用) Description 在一个果园里,多多已经将所有的果子打了下来,而且按果子的不同种类分成了不同的堆.多多决定把所有的果子合成一堆. 每 ...

  2. bzoj1528 sam-Toy Cars(贪心,优先队列)

    「BZOJ1528」[POI2005] sam – Toy Cars Description Jasio 是一个三岁的小男孩,他最喜欢玩玩具了,他有n 个不同的玩具,它们都被放在了很高的架子上所以Ja ...

  3. POJ1862 Stripies 贪心 B

    POJ 1862 Stripies https://vjudge.net/problem/POJ-1862 题目:     Our chemical biologists have invented ...

  4. CF #374 (Div. 2) D. 贪心,优先队列或set

    1.CF #374 (Div. 2)   D. Maxim and Array 2.总结:按绝对值最小贪心下去即可 3.题意:对n个数进行+x或-x的k次操作,要使操作之后的n个数乘积最小. (1)优 ...

  5. sgu548 Dragons and Princesses   贪心+优先队列

    题目链接:http://acm.sgu.ru/problem.php?contest=0&problem=548 题目意思: 有一个骑士,要经过n个房间,开始在第一个房间,每个房间里面有龙或者 ...

  6. poj3190区间类贪心+优先队列

    题意:每个奶牛产奶的时间为A到B,每个奶牛产奶时要占用一间房子,问n头奶牛产奶共需要多少房子,并输出每头奶牛用哪间房子 分析:这题就是一个裸的贪心,将奶牛按开始时间进行排序即可,但考虑一下数据范围,我 ...

  7. 【贪心算法】POJ-1862 简单哈夫曼

    一.题目 Description Our chemical biologists have invented a new very useful form of life called stripie ...

  8. 【BZOJ 3661】 Hungry Rabbit (贪心、优先队列)

    3661: Hungry Rabbit Time Limit: 100 Sec  Memory Limit: 512 MBSec  Special JudgeSubmit: 67  Solved: 4 ...

  9. 2015多校第6场 HDU 5360 Hiking 贪心,优先队列

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5360 题意:给定n个人,现在要邀请这些人去远足,但每个人同意邀请的条件是当前已经同意去远足的人数c必须 ...

随机推荐

  1. 注解方式过滤器(Filter)不能过滤Servlet的问题

    https://www.aliyun.com/jiaocheng/778495.html 今天写filter(过滤器)的时候,碰到一个奇怪的问题,发现filter可以过滤urlPatterns,但是无 ...

  2. Lodop如何打印直线

    Lodop打印设计提供了可视化设计,生成代码的方便,在打印设计界面上,选择添加打印项的时候,可以看到没有添加直线选项,可添加斜线,然后把添加的斜线调整成直线:线宽=高 -----水平直线线宽=宽--- ...

  3. PCIE

    ---恢复内容开始--- 高速差分总线.串行总线 每一条PCIe链路中只能连接两个设备这两个设备互为是数据发送端和数据接收端.PCIe链路可以由多条Lane组成,目前PCIe链路×1.×2.×4.×8 ...

  4. 洛谷-p2764(最小路径覆盖)(网络流24题)

    #include<iostream> #include<algorithm> #include<queue> #include<cstring> #in ...

  5. linux下如何安装mysql和redis

    linux下如何安装mysql(mariadb) linux下如何安装软件? 1. yum安装软件也得注意,一个是配置yum源 1.我们当前的是阿里云的yum源(下载速度特别快) 通过 yum ins ...

  6. ubuntu系统安装mysql(deb-bundle包)

    由于某些原因,又要在ubuntu系统中安装mysql了,之前曾经安装过好多次.都没记下来 以前一直动用源码包来安装,基于两个原因:1.一直用Python写代码.2.想使用文件来安装,而不是通过api ...

  7. Luogu4389 付公主的背包(生成函数+多项式exp)

    显然构造出生成函数,对体积v的物品,生成函数为1+xv+x2v+……=1/(1-xv).将所有生成函数乘起来得到的多项式即为答案,设为F(x),即F(x)=1/∏(1-xvi).但这个多项式的项数是Σ ...

  8. 数据库 -- mysql表操作

    一,存储引擎介绍 存储引擎即表类型,mysql根据不同的表类型会有不同的处理机制 详见:https://www.cnblogs.com/peng104/p/9751738.html 二,表介绍 表相当 ...

  9. 【XSY1544】fixed 数学 强连通图计数

    题目描述 ​ 给你一个\(n\times n\)的方阵\(A\).定义方阵\(A\)的不动点\((i,j)\)为:\(\forall p,q\geq 0,(A^p)_{i,j}=(A^q)_{i,j} ...

  10. Linux qemu-nbd mount qemu disk image

    Linux qemu-nbd mount qemu disk image deepin@deepin:~$ deepin@deepin:~$ qemu-nbd --help Usage: qemu-n ...