标签:des style http color os strong
Time Limit: 1000MS | Memory Limit: 65536K | |
Total Submissions: 31449 | Accepted: 18269 |
Description
Input
Output
Sample Input
5 2 4 1 3 5
Sample Output
3
Hint
Source
#include<iostream> using namespace std; int a[10010]; int partition(int *a,int p,int r){ int x=a[r]; int i=p-1; for(int j=p;j<=r-1;j++){ if(a[j]<x){ i++; int tmp=a[i]; a[i]=a[j]; a[j]=tmp; } } int tmp=a[i+1]; a[i+1]=a[r]; a[r]=tmp; return i+1; } int R_Select(int *a,int p,int r,int i){ if(p==r) return a[p]; int q=partition(a,p,r); int k=q-p+1; if(i==k) return a[q]; else if(i<k) return R_Select(a,p,q-1,i); else return R_Select(a,q+1,r,i-k); } int main(){ int n; while(cin>>n){ for(int i=1;i<=n;i++){ cin>>a[i]; } cout<<R_Select(a,1,n,n/2+1)<<endl; } return 0; }
标签:des style http color os strong
原文地址:http://blog.csdn.net/my_acm/article/details/38060923