Given an odd number of cows N (1 <= N < 10,000) and their milk output (1..1,000,000), find the median amount of milk given such that at least half the cows give the same amount of milk or more and at least half give the same or less.
5 2 4 1 3 5
3
中位数。。。。。。。。。。。。。。。。。。。。。。。。。。。。
#include<iostream> #include<string.h> #include<set> #include<stdio.h> #include<vector> #include<algorithm> #include<numeric> #include<math.h> #include<string.h> #include<sstream> #include<stdio.h> #include<string> #include<cstdlib> #include<algorithm> #include<iostream> #include<map> #include<queue> #include<string> using namespace std; int main() { int n; while (cin>>n) { int i; int x; int sum; vector<int> s; for(i=1;i<=n;i++) { cin>>x; s.push_back(x); } sort(s.begin(),s.end()); cout<<s[n/2]<<endl; } return 0; }