| ||||||||||
| 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 | |||||||||
快排,不过还有好些地方要优化#include<cstdio>
#pragma warning (disable:4996)
using namespace std;
int n;
int arr[10010];
void quickSort(int start,int end)
{
if (start >= end)
return;
int first, last, key;
first = start;
last = end;
key = arr[first];
while (first < last)
{
while (first < last && arr[last] >= key)
last--;
arr[first] = arr[last];
while (first < last && arr[first] <= key)
first++;
arr[last] = arr[first];
}
arr[first] = key;
quickSort(start, first - 1);
quickSort(first + 1, end);
}
int main()
{
//freopen("input.txt", "r", stdin);
//freopen("output.txt", "w", stdout);
while (scanf("%d", &n) != EOF)
{
for (int i = 0; i < n; i++)
scanf("%d", &arr[i]);
quickSort(0, n - 1);
printf("%d\n", arr[n / 2]);
}
return 0;
}
Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator