POJ:1862 Stripies

这个题跟UVA:10954 Add All 有点像。


需要每次计算质量最大的那两个,虽然我也不能说清楚为什么这么做,凭直觉吧。


数据量比较小,每次求最大的那两个用快排都可以。不过我还是使用了插入排序。


#include
#include
#include
#include
#include
using namespace std;
int  main()
{
    //freopen("in.txt","r",stdin);
   int n;
   scanf("%d",&n);
   double a[105]={0};
   for(int i=0;i=2)
   {
       res=2*sqrt(a[n-1]*a[n-2]);
       for(int i=n-3;i>=0;--i)
       if(res

代码中有一些细节值得注意:最大的是倒数后两个,计算完之后就不再考虑了;取出最大的两个以后还要插入一个新的,所以总长度只减少了1。

你可能感兴趣的:(POJ)