zoukankan      html  css  js  c++  java
  • POJ 2388.Who's in the Middle

    Who's in the Middle
    Time Limit:1000MS     Memory Limit:65536KB     64bit IO Format:%I64d & %I64u

    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:oyohyee@oyohyee.com
     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
    ",a[n/2]);
    46 
    47     return true;
    48 }
    49 
    50 int main() {
    51     while(Do());
    52     return 0;
    53 }
  • 相关阅读:
    刷题-力扣-414. 第三大的数
    刷题-力扣-976. 三角形的最大周长
    刷题-力扣-942. 增减字符串匹配
    刷题-力扣-409. 最长回文串
    扛把子组20191121-4 Final发布用户使用报告
    Scrum立会报告+燃尽图 07
    Final发布
    扛把子组20191121-3 Final阶段贡献分配规则
    扛把子组20191121-10 Scrum立会报告+燃尽图 06
    Scrum立会报告+燃尽图 05
  • 原文地址:https://www.cnblogs.com/ohyee/p/5472334.html
Copyright © 2011-2022 走看看