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. Web API2 使用默认Identity

    当您选择个人账户在Web API项目模板,项目包含一个令牌授权服务器验证用户凭证和问题.下面的图显示了相同的凭证流的Web API组件. 发送一个未经授权的请求 首先,运行应用程序并单击按钮调用的AP ...

  2. Qt evenFilter()与installEvenFilter()

    1, eventFilter 函数中实现事件过滤器.请注意:该函数在 QObject 类中声明为一个虚函数,因此只能由 QObject 的子类继承使用. 2, installEventFilter函数 ...

  3. 关于mysql 5.7 版本登录时出现错误 1045的随笔

    之前学习的时候用的都是oracle 但是现在在工作中大部分用的都是mysql,所以自己也就装了个mysql,下载.安装教程都是从网上百度的,花了挺长时间才装好,心也是挺累的,教程挺多,就是不知道该用哪 ...

  4. AIM Tech Round 4 Div. 1

    A:显然最优方案是对所形成的置换的每个循环排个序. #include<iostream> #include<cstdio> #include<cmath> #inc ...

  5. Git——快速安装Git及初始化配置【二】

    文档 https://git-scm.com/book/zh/v2 下载 mac https://git-scm.com/download/mac Linux https://git-scm.com/ ...

  6. 洛谷P2670扫雷游戏题解

    题目 这道题是一个简单的模拟搜索题,可以把每个雷的位置都记作1. 这样就可记录出数字啦 #include<iostream> #include<cstring> using n ...

  7. HDU2204 Eddy's爱好

    题意:给你一个正整数N,确定在1到N之间有多少个可以表示成M^K(K>1)的数. 解析:一个数N 开K次根后得到M  则小于M的所有数的K次方一定小于N 因为任何一个合数都能分解为素数的乘积 所 ...

  8. Quartus prime 16.0 signaltap II 使用

    前言 由于逻辑分析仪太贵,altera贴心提供signal tap II来观察输出波形,不过使能signaltap II会占用片内ram,毕竟原理就是把数据采样到ram中再通过jtag口上传到quar ...

  9. git 出现stderr: error: bad signature fatal: index file corrupt

    命令执行依次: $ rm -f .git/index $ git reset 重启即可

  10. 【转】让浏览器格式化显示JSON数据之chrome jsonView插件安装

    jsonView 用来让Chrome浏览器能格式化的显示JSON数据. 以上是网上找的方式,且试验成功! 步骤: 1.打开 https://github.com : 2.搜索 jsonView 链接: ...