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 |
Re:怎么会WA呢?思路很简单啊In Reply To:怎么会WA呢?思路很简单啊 Posted by:PC0400322032 at 2004-08-09 21:09:15 单纯的贪心肯定是有问题的,例如N=4,个数分别为:5,3,4,5。 ——LouTianCheng > #include <stdio.h> > void main(void) > { > int n,m; > unsigned int a[50005],b[50005],*p,*q,*r; > int i,k; > unsigned c,min,tm; > while(1) > { > scanf("%d",&n); > if(n==0) > break; > for(i=1;i<=n;i++) > scanf("%d",&a[i]); > m = 0;a[0]=b[0]=1000000005; > p = a+1; q = b+1; c = 2; > while(n>1) > { > min = p[n] = 1000000005; > k = 0; > for(i=0;i<n;i++) > { > tm = p[i]+p[i+1]; > if(tm<=c) > { > m += tm; > q[k] = tm; > i++; > } > else > q[k] = p[i]; > if(q[k]+q[k-1]<min) > min = q[k-1]+q[k]; > k++; > } > c = min; > r = p; p = q; q = r; > n = k; > } > printf("%u\n",m); > } > } Followed by:
Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator