POJ 2388 Who's in the Middle 排序
来源:互联网 发布:返利网和淘宝客 编辑:程序博客网 时间:2024/05/18 00:44
题意:输出一串数字的中间数。
题解:
#include <iostream>using namespace std;void quiksort ( int * array, int left, int right ){if ( left < right ){int s = array [( left + right ) / 2]; int l = left - 1, r = right + 1; while ( 1 ){while ( array[++l] < s ); while ( array[--r] > s ); if ( l >= r )break; swap ( array[l], array[r] );} quiksort ( array, left, l - 1 ); quiksort ( array, r + 1, right ); } } int main(){int n, array[10010];cin >> n;for ( int i = 0; i < n; i++ )cin >> array[i];quiksort(array,0,n-1);cout << array[n/2] << endl;return 0;}或者#include <iostream>using namespace std;int array[10010];int part ( int left, int right ){int i = left - 1;int s = array[right];for ( int j = left; j < right; j++ ){if ( array[j] <= s ){i++;swap ( array[i], array[j] );}}swap ( array[right], array[i+1] );return i + 1;}void Qsort ( int left, int right ){if ( left >= right )return;int p = part ( left, right );Qsort(left,p-1);Qsort(p+1,right);}int main(){int n;cin >> n;for ( int i = 0; i < n; i++ )cin >> array[i];Qsort(0,n-1);cout << array[n/2] << endl;return 0;}
- POJ 2388 Who's in the Middle(排序)
- POJ 2388 Who's in the Middle(堆排序)
- POJ 2388 Who's in the Middle 排序
- poj 2388 Who's in the Middle【sort排序】
- Who's in the Middle 堆排序,poj 2388
- POJ 2388 Who's in the Middle(排序)
- poj 2388 Who's in the Middle 排序,大水
- Poj 2388 Who's in the Middle【排序】
- poj 2388Who's in the Middle 排序
- POJ--2388 Who's in the Middle
- poj 2388 Who's in the Middle
- POJ-2388 who's in the middle
- poj-2388 Who's in the Middle
- poj 2388 Who's in the Middle
- POJ 2388 Who's in the Middle
- poj 2388 Who's in the Middle
- POJ 2388 Who's in the Middle
- Poj 2388 Who's in the Middle
- 关于FireBird
- HBase Merging Regions
- GridControl 控件小结
- 二维rmq zoj2859
- CSS笔记2
- POJ 2388 Who's in the Middle 排序
- 定义自己的operator new和operator delete时注意点
- 初识android
- first essay
- PHP如何读写文件
- spring 3.0.5+velocity tools 2.0
- sql一些语句
- 半导体命名办法
- asp.net实现word在线预览功能