zoj 1543 贪心

Stripies


Time Limit: 2 Seconds     
Memory Limit: 65536 KB



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 file 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.

Process to the end of file.

Output

The output file must contain one line with the minimal possible total weight of colony with the accuracy of three decimal digits after the point.

Sample Input

2

72

50

3

72

30

50

Sample Output

120.000

120.000


每次加入最大的,因为sqrt几次就小了,水题

#include<cstdio>
#include<cmath>
#include<algorithm>
#include<cstring>
#include<algorithm>
using namespace std;

#define N 10005

double a[N];

int main()
{
    int n,i;

    while(~scanf("%d",&n))
    {
        for(i=0;i<n;i++)
            scanf("%lf",&a[i]);

        sort(a,a+n);

        double ans=a[n-1];
        n--;
        for(i=n-1;i>=0;i--)
            ans=2*sqrt(ans*a[i]);

        printf("%.3lf\n",ans);
    }
    return 0;
}

zoj 1543 贪心

时间: 2024-10-09 21:07:44

zoj 1543 贪心的相关文章

zoj 3627(贪心)

思路:半夜了思路有点混乱wa了好几发.一开始坑定两个人距离为m才能获得最大的收益,所以我们就可以枚举单个端点,当距离达到m时在一同一个方向走这是我们只需要算一下剩下几秒,左右两边贪心去最大的即可. 代码如下: 1 /************************************************** 2 * Author : xiaohao Z 3 * Blog : http://www.cnblogs.com/shu-xiaohao/ 4 * Last modified : 2

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

题目链接: PKU:http://poj.org/problem?id=1862 ZJU:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=543 Description Our chemical biologists have invented a new very useful form of life called stripies (in fact, they were first called in Russian -

ZOJ - 3715贪心

ZOJ - 3715KindergartenElection 题目大意:幼儿园里正在举办班长选举,除1号小朋友外每个人都会投他最好的朋友,但1号小朋友可以贿赂别人(小伙子有丶想法),被贿赂的小朋友就会把票投给1号小朋友而不是他最好的朋友,对于不同的小朋友贿赂的花费也不同,1号小朋友想要自己是唯一的班长(票数最高),问他最少需要花费多少糖果? 由题目来想,很容易想到贪心,但是不知道怎么贪心.如果是简单让1号是票数最高的小朋友,他每次贿赂都有两种选择,一种是贿赂花费小的人来投他,另一种是贿赂票数比他

Stock (zoj 2921 贪心经典)

Stock Time Limit: 2 Seconds      Memory Limit: 65536 KB Optiver sponsored problem. After years of hard work Optiver has developed a mathematical model that allows them to predict wether or not a company will be succesful. This obviously gives them a

ZOJ 3829 贪心 思维题

http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=3829 现场做这道题的时候,感觉是思维题,自己智商不够,不敢搞,想着队友智商好,他们搞吧,但是没出来这题...... 以后任何时候,都自信点....该想的还是好好自己想,这类题感觉就是先去找性质,然后一点点找规律,如果必要的话,自己提出一点猜想,然后如果自己举不出来反例,就暂时认为是正确的 下午搞了一下午,发现还是悲剧,晚上参考了两个题解 http://blog.csdn.

ZOJ 38727(贪心)

这道题真心坑,越想越远  想的飞起来了, 最后纠结起后缀表达式的定义来了. 题意: 就是给你一个串 ,  让你用最少修改次数来实它变成一个合法的后缀表达式,  修改方式有两种, 一种是直接添加数字或者*,或者是交换两个字符的位置. 题解: 首先保证星号所需要的数字比当前串的数字大,如果不足,则添加需要数字到字符串首 , 然后从头朝尾扫,  如果当前状态合法则不需要管,当前状态不合法的时候将* 号移到最末尾.然后没了 代码: #include<stdio.h> #include<strin

ZOJ 3607 Lazier Salesgirl (贪心)

Lazier Salesgirl Time Limit: 2 Seconds      Memory Limit: 65536 KB Kochiya Sanae is a lazy girl who makes and sells bread. She is an expert at bread making and selling. She can sell the i-th customer a piece of bread for price pi. But she is so lazy

ZOJ 2109 FatMouse&#39; Trade (背包 dp + 贪心)

链接:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=1109 FatMouse prepared M pounds of cat food, ready to trade with the cats guarding the warehouse containing his favorite food, JavaBean. The warehouse has N rooms. The i-th room contains J

zoj 3659 Conquer a New Region 并查集+贪心

点击打开链接题目链接 Conquer a New Region Time Limit: 5 Seconds      Memory Limit: 32768 KB The wheel of the history rolling forward, our king conquered a new region in a distant continent. There are N towns (numbered from 1 to N) in this region connected by s