| ||||||||||
| Online Judge | Problem Set | Authors | Online Contests | User | ||||||
|---|---|---|---|---|---|---|---|---|---|---|
| Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest | |||||||||
http://ace.delos.com/TESTDATA/NOV06_4.htmIn Reply To:纠结啊,运行完全正确,为什么在poj上是WA呢?各位帮帮忙吧,小女子在此不慎感谢! Posted by:liuxiao2009 at 2012-04-11 21:52:24 > #include<stdio.h>
> #include<stdlib.h>
> //重建堆
> void sift(int *a,int k,int n)
> {
> int i,j,t;
> i=k;
> j=2*i;
> t=a[k];
> while(j<=n)
> {
> if(j<n&&a[j]<a[j+1])
> j++;
> if(t<a[j])
> {
> a[i]=a[j];
> i=j;
> j=2*i;
> }
> else
> break;
> }
> a[i]=t;
> }
> //建初堆
> void creat(int *a,int n)
> {
> int i;
> for(i=n/2;i>0;i--)
> {
> sift(a,i,n);
> }
>
> }
> //堆排序
> void heapSort(int *a,int n)
> {
> int i,m;
> creat(a,n);
> for(i=n;i>=2;i--)
> {
> m=a[1];
> a[1]=a[i];
> a[i]=m;
> sift(a,1,i-1);
> }
> }
> int main()
> {
> int i,N;
> int sum1,sum;
> int *a;
>
> scanf("%d",&N);
> a=(int*)malloc((N+1)*sizeof(int));
> for(i=1;i<=N;i++)
> {
> scanf("%d",&a[i]);
> }
> heapSort(a,N);
> //求和
> sum1=a[1];
> sum=0;
> for(i=2;i<=N;i++)
> {
> sum1=sum1+a[i];
> sum=sum+sum1;
> printf("%d--->%d\n",a[i],sum);
> }
> printf("%d\n",sum);
>
> return 0;
> }
Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator