POJ 2338 Who'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,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

题目大意:。。。翻译不明白 总体就是取最中间的数,一个排序就搞定
 1 #include<stdio.h>
 2 main()
 3 {
 4  int n,i,j,a[10001],temp=0,flag;
 5  while(scanf("%d",&n)!=EOF)
 6  {
 7  for(i=0;i<n;i++)
 8  {
 9   scanf("%d",&a[i]);
10  }
11  for(i=0;i<n-1;i++)
12  {
13   for(j=0;j<n-1-i;j++)
14   {
15    if(a[j]>a[j+1])
16    {
17     temp=a[j];
18     a[j]=a[j+1];
19     a[j+1]=temp;
20    }
21   }
22  }
23  printf("%d\n",a[n/2]);
24  }
25  return 0;
26 }

POJ 2338 Who's in the Middle

时间: 2024-10-24 13:41:15

POJ 2338 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

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

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 1198 / hdu 1401 Solitaire (记忆化搜索+meet in middle)

题目大意:给你一个8*8的棋盘,上面有四个棋子,给你一个初始排布,一个目标排布,每次移动,可以把一个棋子移动到一个相邻的空位,或者跨过1个相邻的棋子,在保证棋子移动不超过8次的情况下,问能否把棋盘上的棋子由初始排布变成目标排布 8*8的棋盘,刚好不爆ull,状压那些位置有棋子 然后从初始状态开始,暴搜出当前状态下,移动一个棋子之后所有可能到达的状态 直接搜,总状态数是8^8,此外还有常数,会爆 由于给定了目标排布,考虑meet in middle 从起始状态和目标状态各搜4步即可 为了防止爆栈,

Poj 2010-Moo University - Financial Aid

Moo University - Financial Aid 题目链接:http://poj.org/problem?id=2010 Time Limit: 1000MS   Memory Limit: 30000K Total Submissions: 9046   Accepted: 2640 Description Bessie noted that although humans have many universities they can attend, cows have none

poj 3069 Saruman&#39;s Army

Saruman's Army Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 5760   Accepted: 2949 Description Saruman the White must lead his army along a straight path from Isengard to Helm’s Deep. To keep track of his forces, Saruman distributes se

poj 1221

J - UNIMODAL PALINDROMIC DECOMPOSITIONS Time Limit:1000MS     Memory Limit:65536KB     64bit IO Format:%I64d & %I64u Submit Status Practice POJ 1221 Appoint description:  System Crawler  (2014-11-16) Description A sequence of positive integers is Pal

UVA 322 ships (POJ 1138)

题目地址: http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=258 http://poj.org/problem?id=1138 题目描写叙述:  Ships  Probably everyone who ever attended school knows the game where two opposing players place