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 |
read faqIn Reply To:我的程序超时了(超了15ms),不知怎么改才好,恳请尊敬的的各位帮一忙,小弟不胜感激 Posted by:acmgotogether at 2006-04-18 01:29:31 > #include<iostream> > using namespace std; > int max(int a,int b) > { > if(a>=b) > return a; > else > return b; > } > > int main() > { > int n;int sum1=0,sum2=0,s;int T; > cin>>T; > for(int l=1;l<=T;l++) > { > > cin>>n; > int *a=new int [n]; > for(int i=0;i<n;i++) > { > cin>>a[i]; > } > > for(int s1=0;s1<=n-2;s1++) > for(int t1=s1;t1<=n-2;t1++) > for(int s2=t1+1;s2<=n-1;s2++) > for(int t2=s2;t2<=n-1;t2++) > { > > for(int ii=s1;ii<=t1;ii++) > { > sum1+=a[ii]; > } > for(int jj=s2;jj<=t2;jj++) > { > sum2+=a[jj]; > } > > if(s1==0&&t1==0&&s2==1&&t2==1){s=sum1+sum2;sum1=0;sum2=0;} > else > {s=max(sum1+sum2,s);sum1=0;sum2=0;} > > > } > cout<<s<<endl; > } > > return 0; > } > > > > > > Followed by:
Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator