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 2sqrt(m1m2). 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

这个题是一个明显的贪心问题

#include<iostream>
#include<cmath>
#include<algorithm>
using namespace std;
const int maxn=101;
void qrt(const double &x,double &b);
bool cmp(int ax,int bx)
{
return ax>bx;
}
int main()
{
int n;
cin>>n;
double a[maxn];
for(int i=0;i<n;i++)
{
cin>>a[i];
}
sort(a,a+n,cmp);
for(int i=0;i<n-1;i++)
{
qrt(a[i],a[i+1]);
} // cout<<a[n-1];
printf("%.3f\n",a[n-1]);
return 0;
}
void qrt(const double &x,double &b)
{
b=2*sqrt(x*b);
}

STL 训练 POJ - 1862 Stripies的更多相关文章

  1. poj 1862 Stripies/优先队列

    原题链接:http://poj.org/problem?id=1862 简单题,贪心+优先队列主要练习一下stl大根堆 写了几种实现方式写成类的形式还是要慢一些... 手打的heap: 1: #inc ...

  2. POJ 1862 Stripies 贪心+优先队列

    http://poj.org/problem?id=1862 题目大意: 有一种生物能两两合并,合并之前的重量分别为m1和m2,合并之后变为2*sqrt(m1*m2),现在给定n个这样的生物,求合并成 ...

  3. POJ 1862 Stripies (哈夫曼树)

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

  4. POJ 1862 Stripies【哈夫曼/贪心/优先队列】

    Stripies Time Limit: 1000MS   Memory Limit: 30000K Total Submissions: 18198   Accepted: 8175 Descrip ...

  5. POJ 1862 Stripies#贪心(水)

    (- ̄▽ ̄)-* #include<iostream> #include<cstdio> #include<cmath> #include<algorithm ...

  6. POJ 1862 Stripies

    每次合并最大的两个,优先级队列维护一下. 输出的时候%.3lf G++会WA,C++能AC,改成%.3f,都能AC. #include<cstdio> #include<cstrin ...

  7. POJ 1862 Stripies 【优先队列】

    题意:科学家发现一种奇怪的东西,他们有重量weight,如果他们碰在一起,总重变成2*sqrt(m1*m2).要求出最终的重量的最小值. 思路:每次选取质量m最大的两个stripy进行碰撞结合,能够得 ...

  8. 几道STL题目(FJUT - OJ STL训练1)

    这个OJ一直在做,一些专题题目都很好,从易至难,阶梯上升,很适合像我这样的蒟蒻 =7= 这篇是关于其中一个专题训练的题解思路及代码   http://120.78.128.11/Contest.jsp ...

  9. POJ 1862 &amp; ZOJ 1543 Stripies(贪心 | 优先队列)

    题目链接: PKU:http://poj.org/problem?id=1862 ZJU:http://acm.zju.edu.cn/onlinejudge/showProblem.do?proble ...

随机推荐

  1. SQLAlchemy查询

    SQLAlchemy查询 结果查询: from databases.wechat import User from config import session def search(): result ...

  2. javascript 入门 select2

    要说这select2,还真是我......,也不是难,反正就对不了!!! 我博客看了一下牛,愣是对不了,后来硬着头看着官方文档,终于出来了. 注意: 1.调用的jquery库一定要能用,网上很多不能用 ...

  3. 抽签小程序,妈妈再也不用担心谁洗碗(分配任务)了,so easy

    背景 今天谁炒菜,谁洗碗,谁买菜...啊,Boss说用抽签吧,于是有了下图 这样存在作弊的问题(记住棍子特征,谁先,谁后抽等等)于是有了这个抽签小程序(当然小程序我一个人控制,我想不想作弊看心情了) ...

  4. 30.5 Map遍历方法

    package day30_2_Map; import java.util.HashMap; import java.util.Map; import java.util.Set; /* 方法一.用e ...

  5. SpringBoot入门系列(十一)统一异常处理的实现

    前面介绍了Spring Boot 如何整合定时任务已经Spring Boot 如何创建异步任务和定时任务.不清楚的朋友可以看看之前的文章:<Spring Boot 入门系列文章> 接下来主 ...

  6. Retrofit 网络访问框架简单使用

    1.引入远程依赖:包括okhttp;retrofit2;retrofit的GSON解析器 compile'com.squareup.okhttp3:okhttp:3.2.0' compile'com. ...

  7. 利用Ajax实现异步请求

    Ajax 1.课程引入      静态网站和动态网站都是同步的,但同步方式有缺点:页面请求响应式阻塞,影响用户体验      为了解决这个问题,可以通过变通的手段实现页面的局部更新(隐藏帧),由于隐藏 ...

  8. js操作svg整体缩放

    首先我们先创建一个svg整体布局,代码如下: <!DOCTYPE html> <html> <head> <title>js操作svg实现整体缩放< ...

  9. Android应用架构分析

    一.res目录: 1.属性:Android必需: 2.作用:存放Android项目的各种资源文件.这些资源会自动生成R.java. 2.1.layout:存放界面布局文件. 2.2.strings.x ...

  10. 用python画出全球疫情趋势变化图

    前言 文的文字及图片来源于网络,仅供学习.交流使用,不具有任何商业用途,版权归原作者所有,如有问题请及时联系我们以作处理. 作者:谦睿科技 PS:如有需要Python学习资料的小伙伴可以加点击下方链接 ...