zoukankan      html  css  js  c++  java
  • SDAU课程练习--problemQ(1016)

    题目描述

    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
    

    题目大意

    十足的水题,排序后找出中位数即可

    AC代码

    1. #include<iostream>
    2. #include<stdio.h>
    3. #include<algorithm>
    4. using namespace std;
    5. int a[10000];
    6. int main()
    7. {
    8. //freopen("date.in", "r", stdin);
    9. //freopen("date.out", "w", stdout);
    10. int N;
    11. while (~scanf("%d", &N))
    12. {
    13. //memset(a, 0, 10000 * sizeof(int));
    14. for(int i = 0; i < N; i++)
    15. {
    16. cin>>a[i];
    17. }
    18. sort(a, a + N);
    19. cout << a[(N + 1) / 2-1];
    20. }
    21. }




  • 相关阅读:
    POJ2524+并查集
    POJ3697+BFS+hash存边
    POJ1151+线段树+扫描线
    POJ2528+线段树
    ubuntu 和 win7 远程登陆 + vnc登陆
    POJ3690+位运算
    POJ3283+字典树
    POJ3282+模拟
    POJ2349+prim
    2016.6.13
  • 原文地址:https://www.cnblogs.com/liuzhanshan/p/5353010.html
Copyright © 2011-2022 走看看