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 |
用冒泡当然超时!用快排都200多MS!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: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator