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

Re:可以O(n)的

Posted by ArXoR at 2005-03-05 22:52:46 on Problem 2231
In Reply To:求助~实在是束手无策了!~为什么会老是TLE Posted by:ray58750034 at 2005-03-05 22:50:10
> <p>
> #include <iostream>
>  using namespace std;
> 
> int main1()
> {
>     short n,i,j;
>     unsigned temp;
>     cin>>n;
>     long long sum=0;
> 	unsigned* data=new unsigned[n];
> 	for(i=0;i<n;i++)
> 	    cin>>data[i];
>     for(i=0;i<n-1;i++){
>         for(j=i+1;j<n;j++){
>             if(data[j]>=data[i])
>             temp=(data[j]-data[i]);
>             else
>             temp=(data[i]-data[j]);
>             sum+=temp;
> 		}
>    }
>   cout <<sum*2 <<endl;
>     return 0;
> }
> </p>

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