poj2623,

## Problem:

Sequence Median
 Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 11187 Accepted: 3201
Description
Given a sequence of N nonnegative integers. Let's define the median of such sequence. If N is odd the median is the element with stands in the middle of the sequence after it is sorted. One may notice that in this case the median has position (N+1)/2 in sorted sequence if sequence elements are numbered starting with 1. If N is even then the median is the semi-sum of the two "middle" elements of sorted sequence. I.e. semi-sum of the elements in positions N/2 and (N/2)+1 of sorted sequence. But original sequence might be unsorted.

Your task is to write program to find the median of given sequence.
Input
The first line of input contains the only integer number N - the length of the sequence. Sequence itself follows in subsequent lines, one number in a line. The length of the sequence lies in the range from 1 to 250000. Each element of the sequence is a positive integer not greater than 2^32 - 1 inclusive.
Output
You should print the value of the median with exactly one digit after decimal point.
Sample Input
```4
3
6
4
5
```
Sample Output
`4.5`
Hint
Huge input,scanf is recommended.
Source
Ural Collegiate Programming Contest 1998

Solution:

## Source Code:

//Sat Apr 16 14:42:56 CDT 2011
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <ctime>

using namespace std;

vector<double> v;

void init(int N) {
v.resize(N);
for (int i = 0; i < N; i++)
cin >> v[i];
}

void process(int N) {
sort(v.begin(), v.end());
if (N % 2 == 1)
printf("%.1f\n", v[(N - 1) / 2]);
else
printf("%.1f\n", (v[(N + 1) / 2] + v[(N - 1) / 2]) / 2);
}

int main(int argc, const char* argv[]) {
//  freopen("input.in", "r", stdin);
//freopen("output.out", "w", stdout);
int N;
cin >> N;
init(N);
process(N);
//  fclose(stdin);
//fclose(stdout);
return 0;
}