• 暑假集训(2)第五弹 ----- Who's in the Middle(poj2388)


    G - Who's in the Middle

    Crawling in process... Crawling failed Time Limit:1000MS     Memory Limit:32768KB     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. 

    问题分析:终于有一道我能称之为水题的水题出现了0.0直接冒泡排序,再求中位数可过,不过我用的STL的sort();0.0
     1 #include "iostream"
     2 #include "algorithm"
     3 using namespace std;
     4 int *cow;
     5 void cowbegin(int n)
     6 {
     7     int x;
     8     for (int i=0;i<n;i++)
     9       cin>>cow[i];
    10 }
    11 int main()
    12 {
    13     int n,x;
    14     while (cin>>n)
    15     {
    16        cow = new int [n];
    17        cowbegin(n);
    18        sort(cow,cow+n);
    19        cout<<cow[n/2]<<endl;
    20        delete [] cow;
    21     }
    22 
    23     return 0;
    24 }
    View Code






  • 相关阅读:
    CentOS7使用firewalld打开关闭防火墙与端口
    ssh连接卡在【To escape to local shell, press 'Ctrl+Alt+]'.】的解决方法
    本地链路地址
    RIFF和WAVE音频文件格式
    声音分贝的概念,dBSPL.dBm,dBu,dBV,dBFS
    VS中C++ 项目重命名
    FFmpeg学习6:视音频同步
    FFmpeg学习5:多线程播放视音频
    FFmpeg学习4:音频格式转换
    FFmpeg数据结构:AVPacket解析
  • 原文地址:https://www.cnblogs.com/huas-zlw/p/5697017.html
Copyright © 2020-2023  润新知