zoukankan      html  css  js  c++  java
  • 暑假集训(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






  • 相关阅读:
    JDBI
    Concise: Compressed ’n’ Composable Integer Set
    java 7 新特性
    BIO的简单Demo
    手写一个死锁Demo
    实现一个Cglib代理Demo
    实现一个JDK代理demo
    ClassNotFoundException和 NoClassDefFoundError区别验证
    集合—ArrayList
    Hadoop之Storm基础
  • 原文地址:https://www.cnblogs.com/huas-zlw/p/5697017.html
Copyright © 2011-2022 走看看