http://poj.org/problem?id=1862
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.
题意:重量为m1的生物与重量为m2的生物合并后变为一个生物,该生物的重量为2*sqrt(m1*m2)。求给定数量的生物合并成一个生物后的最小重量。
贪心策略是使尽量使大的数多参与开放运算。每次取出最大和次大的变形虫杂交,直至剩下一条光棍。使用最大堆可以很高效地维持最大的数
http://blog.csdn.net/vickey1018/article/details/19022297
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.
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 50http://www.hankcs.com/program/cpp/poj-1862-stripies.html
题意:重量为m1的生物与重量为m2的生物合并后变为一个生物,该生物的重量为2*sqrt(m1*m2)。求给定数量的生物合并成一个生物后的最小重量。
贪心策略是使尽量使大的数多参与开放运算。每次取出最大和次大的变形虫杂交,直至剩下一条光棍。使用最大堆可以很高效地维持最大的数
http://blog.csdn.net/vickey1018/article/details/19022297
基本不等式: a+b>=2*sqrt(a*n)> max(a,b)
一个贪心的想法,原先质量越大的,如果越先被计算,那么开根号的次数就会越多,相比之下,最终结果就会越小。
Read full article from 1862 -- Stripiesint
main(
int
argc,
char
*argv[])
{
#ifndef ONLINE_JUDGE
freopen
(
"in.txt"
,
"r"
, stdin);
freopen
(
"out.txt"
,
"w"
, stdout);
#endif
int
N;
cin >> N;
priority_queue<
double
> que;
for
(
int
i = 0; i < N; ++i)
{
double
l;
cin >> l;
que.push(l);
}
while
(que.size() != 1)
{
double
a = que.top(); que.pop();
double
b = que.top(); que.pop();
que.push(2 *
sqrt
(a * b));
}
cout.setf(ios::fixed);
cout.precision(3);
cout << que.top() << endl;
#ifndef ONLINE_JUDGE
fclose
(stdin);
fclose
(stdout);
system
(
"out.txt"
);
#endif
return
0;
}