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. 11/1/2018模拟 Max

    题面 也就是说, 随机序列RMQ.(\(n \le 8388608\), \(m \le 8*10^6\)) 解法 我写了笛卡尔树+tarjan 然而听神仙说, 因为数据随机, 建完树暴力找lca就行 ...

  2. Nginx 多核cpu负载均衡

    L:122 查看Linux CPU 缓存大小 cat /sys/devices/system/cpu/cpu1/cache/index0/size //指令缓存 cat /sys/devices/sy ...

  3. Java精品文章收藏

    1.JAVA进阶----ThreadPoolExecutor机制 待实践测试

  4. HTML知识点总结[部分]

    Web服务的本质(socket实例) import socket def handle_request(client): buf = client.recv(1024) client.send(byt ...

  5. Elasticsearch 删除数据

    删除数据分为两种:一种是删除索引(数据和表结构同时删除,作用同SQLSERVER 中 DROP TABLE "表格名" ),另一种是删除数据(不删除表结构,作用同SQLSERVER ...

  6. python中的replace()方法的使用

    python中的replace()方法的使用 需求是这样的:需要将字符串的某些字符替换成其他字符 str.replace(old,new,max) 第一个参数是要进行更换的旧字符,第二个参数是新的子串 ...

  7. MT【287】余弦的线性组合

    (2017北大特优)在$\Delta ABC$中,$cos A+\sqrt{2}cos B+\sqrt{2}cos C$的最大值____ 解答 :2$cos A+\sqrt{2}cos B+\sqrt ...

  8. 使用 Zabbix 监控 Jenkins

    笔者最近的工作涉及到使用 Zabbix 监控 Jenkins.在谷歌上搜索到的文章非常少,能操作的就更少了.所以决定写一篇文章介绍如何使用 Zabbix 监控 Jenkins. 下图为整体架构图: 整 ...

  9. Python将是人工智能时代的最佳编程语言

    Python将是人工智能时代的最佳编程语言 移动互联网取代PC互联网领跑在互联网时代的最前沿,Android和iOS一度成为移动互联网应用平台的两大霸主,成为移动开发者首选的两门技术,HTML5以其跨 ...

  10. Hdoj 1232.畅通工程 题解

    Problem Description 某省调查城镇交通状况,得到现有城镇道路统计表,表中列出了每条道路直接连通的城镇.省政府"畅通工程"的目标是使全省任何两个城镇间都可以实现交通 ...