POJ 2388.Who's in the Middle

Who‘s in the Middle

Time Limit:1000MS     Memory Limit:65536KB     64bit IO Format:%I64d & %I64u

Submit Status Practice POJ 2388

Description

FJ is surveying his herd to find the most average cow. He wants to know how much milk this ‘median‘ cow gives: half of the cows give as much or more than the median; half give as much or less.

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.

Input

* Line 1: A single integer N

* Lines 2..N+1: Each line contains a single integer that is the milk output of one cow.

Output

* Line 1: A single integer that is the median milk output.

Sample Input

5
2
4
1
3
5

Sample Output

3

Hint

INPUT DETAILS:

Five cows with milk outputs of 1..5

OUTPUT DETAILS:

1 and 2 are below 3; 4 and 5 are above 3.

对一组数求其中位数(连有两个中位数的情况都不用考虑)

直接排序即可

AC代码:GitHub

 1 /*
 2 By:OhYee
 3 Github:OhYee
 4 HomePage:http://www.oyohyee.com
 5 Email:[email protected]
 6 Blog:http://www.cnblogs.com/ohyee/
 7
 8 かしこいかわいい?
 9 エリーチカ!
10 要写出来Хорошо的代码哦~
11 */
12
13 #include <cstdio>
14 #include <algorithm>
15 #include <cstring>
16 #include <cmath>
17 #include <string>
18 #include <iostream>
19 #include <vector>
20 #include <list>
21 #include <queue>
22 #include <stack>
23 #include <map>
24 using namespace std;
25
26 //DEBUG MODE
27 #define debug 0
28
29 //循环
30 #define REP(n) for(int o=0;o<n;o++)
31
32 const int maxn = 10005;
33 int a[maxn];
34
35 bool Do() {
36     int n;
37     if(scanf("%d",&n) == EOF)
38         return false;
39
40     REP(n)
41         scanf("%d",&a[o]);
42
43     sort(a,a + n);
44
45     printf("%d\n",a[n/2]);
46
47     return true;
48 }
49
50 int main() {
51     while(Do());
52     return 0;
53 }

POJ 2388.Who's in the Middle

时间: 2024-08-05 07:07:17

POJ 2388.Who's in the Middle的相关文章

POJ 2388 Who&#39;s in the Middle(水~奇数个数排序求中位数)

题目链接:http://poj.org/problem?id=2388 题目大意: 奇数个数排序求中位数 解题思路:看代码吧! AC Code: 1 #include<stdio.h> 2 #include<algorithm> 3 using namespace std; 4 int main() 5 { 6 int n; 7 while(scanf("%d",&n)!=EOF) 8 { 9 int na[n+1]; 10 for(int i=0; i

POJ 2388 Who&#39;s in the Middle 快排解法

passport.baidu.com/?business&un=%E5%B0%91%E5%A6%87%E8%8C%8C%E5%B9%B3%E5%93%AA%E6%9C%89%E6%89%BE#0 passport.baidu.com/?business&un=%E5%85%A8%E5%A5%97%E8%8E%98%E5%8E%BF%E6%89%BE%E6%9C%8D%E5%8A%A1#0 passport.baidu.com/?business&un=%E9%AB%98%E5%94

POJ 2388:Who&#39;s in the Middle

Who's in the Middle Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 31015   Accepted: 17991 Description FJ is surveying his herd to find the most average cow. He wants to know how much milk this 'median' cow gives: half of the cows give

poj 2388 insert sorting

/** \brief poj 2388 insert sorting 2015 6 12 * * \param * \param * \return * */ #include <iostream> #include <cstdio> #include <cstring> using namespace std; const int N=10000; int Arr[N]; void insertSort(int len) { for(int j=1;j<len;

POJ 2338 Who&#39;s in the Middle

Description FJ is surveying his herd to find the most average cow. He wants to know how much milk this 'median' cow gives: half of the cows give as much or more than the median; half give as much or less. Given an odd number of cows N (1 <= N < 10,0

POJ 2388(排序)

http://poj.org/problem?id=2388 题意:就N个数的中位数. 思路:用快排就行了.但我没用快排,我自己写了一个堆来做这个题.主要还是因为堆不怎么会,这个拿来练练手. 1 #include <stdio.h> 2 #include <string.h> 3 4 int arr[10005],ans,n; 5 6 void inset(int x,int y) //插入,并排序. 7 { 8 int i; 9 for(i = y; arr[ i / 2 ] &

POJ 2388

我不明白为何遇到这种水我竟然要犹豫一下....等会要去走亲戚,刷个水玩玩 #include <iostream> #include <cstdio> #include <algorithm> #include <cstring> using namespace std; long long a[10010]; int main() { int n; while(~scanf("%d",&n)){ memset(a,0,sizeof

poj 2388 快速排序

我实在是太懒了,水过吧 #include<iostream> #include<algorithm> using namespace std; const int MAXN = 1E4; int a[MAXN+1]; int main() { int N; cin>>N; for(int i = 0;i<N;i++) cin>>a[i]; sort(a,a+N); cout<<a[N/2]<<endl; } 原文地址:https

2388 Who&amp;#39;s in the Middle(简单排序)

训练计划的第一个问题,首先从水问题开始:排序的数组,中间数则输出. http://poj.org/problem?id=2388 冒泡排序: #include <iostream> using namespace std; int main() { int i, j, n,t; int a[10000]; cin>>n; for(i=0; i<n; i++) { cin>>a[i]; } //冒泡排序 for(i=0; i<n-1; i++) for(j=0