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 |
贪心法就是错误,这个题应该是NPC吧?NPC必然要全搜的In Reply To:请教!关于我的算法 Posted by:00448213 at 2005-04-22 20:27:00 > 我的算法:先算出总长度,找出数组中最大的数,然后将此数递增,直至可将总长度整除为止。便一相情愿,自作多情的认为此时的数就是所求的。请问高手我的算法的错误(最好给个测试数据),谢谢!代码如下: > # include <iostream.h> > void main() > { > int n,sum=0; > int a[64]; > while(1){ > cin>>n; > if(n==0) > break; > else{ > for(int i=0;i<n;i++){ > cin>>a[i]; > sum += a[i]; > } > int max=a[0]; > for(i=0;i<n;i++) > if(max<a[i]) > max=a[i]; > for(int x=max;;x++) > if(sum%x==0){ > cout<<x<<endl; > sum=0; > break; > } > } > } > } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator