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

用冒泡当然超时!用快排都200多MS!

Posted by zfacmilan at 2007-08-28 11:47:54 on Problem 2371
In Reply To:Why time limit exceed Posted by:baichen at 2006-08-31 21:30:52
#include <iostream>
using namespace std;
void SWAP(int &a,int &b)
{
	int p;
	p=a;
	a=b;
	b=p;
}
void quicksort(int list[ ], int left, int right)
{
    int  pivot, i, j ;
    if ( left < right ){
       i=left;   
	   j=right+1;
       pivot=list[left]; 
       do{
           do
		   i++;
           while (list[ i ]< pivot);
           do            
		   j--;
           while (list[ j ]> pivot); 
           if  ( i < j )SWAP(list [ i ],list [ j ]);
        }  while ( i < j );
        SWAP( list [ left ], list [ j ]);
        quicksort( list, left, j-1);
        quicksort( list, j+1, right);
    } 
}



int main()
{
    int n,m,a[100000],b[100];
    char s[5];
    cin>>n;
    for(int i=0;i<n;i++)
    {
            cin>>a[i];
    }
    quicksort(a,0,n-1);
    cin>>s;
    cin>>m;
    while(m)
    {
            int c;
            cin>>c;
            cout<<a[c-1]<<endl;
            m--;
    }
    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