Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
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: