课程练习一 Problem Q id 1016

来源:互联网 发布:如何优化兵团经济结构 编辑:程序博客网 时间:2024/05/16 12:40

*题目编号  Problem Q    id: 1016


*简单题意 :求一组数中大于一半数,小于等于另一半数的数


*解题思路   输入,排序,输出第a[n-1]/2 的值


*感想:终于碰到一个简单题了



*AC代码

 # include<stdio.h>
 # include<algorithm>
using namespace std;
int main()
{
    int N,a[10001];
    scanf("%d",&N);
    for(int i=0;i<N;i++)
    {
        scanf("%d",&a[i]);
    }
    sort(a,a+N);
    printf("%d",a[(N-1)/2]);
    return 0;
}




Problem Q

Time Limit : 2000/1000ms (Java/Other)   Memory Limit : 131072/65536K (Java/Other)
Total Submission(s) : 88   Accepted Submission(s) : 49
Problem 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<br><br>* 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
524135
 

Sample Output
3
 

Statistic |Submit | Back

0 0
原创粉丝点击