题目大意:给你一堆数,两两结合,答案为2*sqrt(x1*x2),问组合成一个数时,最小的量?
超级无敌大水题,排序或者用堆都可以,反正就是优先组合大的,让根号一直把大数开根降低整体的大小
#include <iostream>
#include <functional>
#include <algorithm>
#include <math.h> using namespace std; typedef int Heap, Position;
static Heap Stripes[]; static int Heap_size = ;
void Insert(const int, Position);
int Delete_Max(void); void Insert(const int item, Position pos)
{
Position s, pr; for (s = pos; s > ; s = pr)//大元素上滤
{
pr = s % == ? s >> : (s - ) >> ;
if (Stripes[pr] < item)
Stripes[s] = Stripes[pr];
else break;
}
Stripes[s] = item;
} int Delete_Max(void)
{
int max = Stripes[], tmp = Stripes[Heap_size--];
Position pr = , s1, s2, s; for (; pr <= Heap_size;)
{
s1 = pr << ; s2 = s1 + ;
if (s2 <= Heap_size)
{
s = Stripes[s1] > Stripes[s2] ? s1 : s2;
Stripes[pr] = Stripes[s];
pr = s;
}
else
{
if (s1 <= Heap_size)
{
Stripes[pr] = Stripes[s1];
pr = s1;
}
break;
}
}
Insert(tmp, pr);
return max;
} int main(void)
{
int n,tmp;
double ans = ; while (~scanf("%d", &n))
{
for (int i = ; i < n; i++)
{
scanf("%d", &tmp);
Insert(tmp, ++Heap_size);
}
ans = (double)Delete_Max();//处理初始情况
for (int i = ; i < n; i++)
ans = * sqrt(ans*(double)Delete_Max());
printf("%.3f", ans);
}
return ;
}
实在是太简单,我自己用自己写的堆实现了一下,数据量也很小,才100,洪水不解释