POJ3253(赫夫曼树)

POJ3253(赫夫曼树)
Source Code

Problem: 
3253   User: ccnu_xieshuo 
Memory: 260K  Time: 282MS 
Language: C
++   Result: Accepted 

Source Code 
#include
< iostream >
#include
< algorithm >
using   namespace  std;

int  main()
{
    
int n;
    
int cuts[20005];
    
int i,j;
    scanf(
"%d",&n);
    
for(i=0;i<n;i++)
        scanf(
"%d",&cuts[i]);
    sort(cuts,cuts
+n);
    __int64 sum
=0;
    
for(i=1;i<n;i++)
    
{
        cuts[i]
+=cuts[i-1];
        sum
+=cuts[i];
        
for(j=i;j<n-1&&cuts[j]>cuts[j+1];j++)
            
//swap(cuts[j],cuts[j+1]);
        {
            
int t=cuts[j];
            cuts[j]
=cuts[j+1];
            cuts[j
+1]=t;
        }

    }

    printf(
"%I64d\n",sum);
    
return 0;
}

你可能感兴趣的:(POJ3253(赫夫曼树))