Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

read faq

Posted by Ikki at 2006-04-18 08:02:19 on Problem 2479
In 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:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator