Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

谁救救我啊~为什么总是WA啊~?谁有测试数据的啊?

Posted by stchou at 2009-12-19 00:33:55 on Problem 3253
#include<stdio.h>
void min_heappify(long a[],long i,int n)
{
 long l,r,min,tmp;
 l=i*2; r=i*2+1;
 if (l<=n&&a[l]<a[i])
  min=l;
 else
  min=i; 
 if (r<=n&&a[r]<a[min])
  min=r;
 if (min!=i)
  {
   tmp=a[min];
   a[min]=a[i];
   a[i]=tmp;
   min_heappify(a,min,n);
  }
}
void build_min_heap(long a[],long n)
{
 long i;
 for (i=n/2;i>=1;--i)
  min_heappify(a,i,n);
}
main()
{
 long a[2000],n,i,min;
 __int64 sum=0;
 scanf("%ld",&n);
 for (i=1;i<=n;i++)
  scanf("%ld",&a[i]);
 build_min_heap(a,n);
 for(i=1;i<n-1;i++)
 {
  min=2;
  if (a[2]>a[3]) min=3;
  sum+=a[1]+a[min];
  a[min]=a[1]+a[min];
  a[1]=a[n-i+1];
  min_heappify(a,1,n-i);
 }
 sum+=a[1]+a[2];
 printf("%I64d",sum);
}

Followed by:

Post your reply here:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator