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 |
牛人帮我看看,这个程序错在哪里,怎么老是通不过啊In Reply To:http://www.oursci.org/magazine/200204/020411-01.htm Posted by:chgsh8089 at 2006-03-25 02:35:08 该程序是在VC6.0下编译通过的 #include<iostream.h> int Case[20]; int a[1000]; int arrLength=0; int iTime=0; void sortArray(int N) { int temp; for(int i=0;i<N;i++) for(int j=i+1;j<N;j++) { if(a[i]>a[j]) { temp=a[i];a[i]=a[j];a[j]=temp; } } } void FindSoul() { if(arrLength==2) iTime+=a[1]; else if(arrLength==3) iTime+=a[0]+a[1]+a[2]; else { if(a[1]*2<=(a[arrLength-2]+a[0])) { iTime+=a[0]+2*a[1]+a[arrLength-1]; arrLength-=2; FindSoul(); } else { iTime+=2*a[0]+a[arrLength-1]+a[arrLength-2]; arrLength-=2; FindSoul(); } } } void main() { int M; cin>>M; for(int i=0;i<M;i++) { int N; cin>>N; for(int t=0;t<N;t++) cin>>a[t]; sortArray(N); arrLength=N; FindSoul(); Case[i]=iTime; iTime=0; } for(int k=0;k<M;k++) cout<<Case[k]<<endl; } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator