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. 如何强制关闭LODOP或c-lodop已经弹出的预览窗口

    该文介绍一下LODOP和C-LODOP关于窗口的弹出,和如何强制关闭已经打开的预览窗口. 同一个页面,只能弹出一个窗口,lodop是禁止点击动作,而c-lodop会提示已有窗口开的,请关闭之类的默认提 ...

  2. Linux系统下手把手完成无人值守安装服务

    刚入职的运维新手经常会被要求去做一些安装操作系统的工作,如果按照用镜像光盘安装操作系统,效率会相当低下.那么如何提升效率,搭建出一套可以批量安装Linux系统的无人值守的安装系统? PXE+TFTP+ ...

  3. delegate--委托

    delegate--委托 (可以把委托看成用来执行方法的一个东西) eg: namespace delegateTest{ delegate double MathsOp(double x); cla ...

  4. node.js 高级功能

    一.Web 模块 1.http 请求(client.js) var http = require('http'); // 用于请求的选项 var options = { host: 'localhos ...

  5. linq之group by 的使用

    group by var list = from s in _sysBll.GetList(s => s.ParamID == "TraSchType" && ...

  6. Windows服务一直“正在启动”怎么杀

    转载:https://blog.csdn.net/huanglong8/article/details/71156848 PS:cmd 记得使用 管理员身份运行 这里需要通过控制台 命令行来查询PID ...

  7. 【XSY1591】卡片游戏 DP

    题目描述 有标有数字为\(1\)~\(9\)的卡片各\(a_1,a_2\cdots a_9\)张,还有标有乘号的卡片\(m\)张.从中取出\(n\)张按任意顺序排列,取出两个乘号相邻和乘法在边界上的非 ...

  8. 微信小程序原生开发简介

    简介: 总结: 1. 逻辑层使用js引擎,视图层使用webview渲染 2. 微信小程序已经支持了绝大部分的 ES6 API 3. 可以自动补全css的兼容语法 文档:https://develope ...

  9. 线性基求第k小异或值

    题目链接 题意:给由 n 个数组成的一个可重集 S,每次给定一个数 k,求一个集合 \(T \subseteq S\), 使得集合 T 在 S 的所有非空子集的不同的异或和中, 其异或和 \(T_1 ...

  10. centos install redmine (项目管理工具)

    安装环境:Centos.mysql.Ruby.Apache.Redmineyum updateyum -y groupinstall "Development Tools"yum ...