题目链接:点击打开链接

Who's in the Middle

Time Limit: 1000MS   Memory Limit: 65536K
Total Submissions: 45683   Accepted: 26310

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

题目大意:找中间数

思路:sort 然后a【n/2】;

AC代码:

#include<cstdio>
#include<iostream>
#include<algorithm>
using namespace std;

int a[10010];
int n;

int main() {
	while(~scanf("%d", &n)) {
		for(int i = 0; i < n; i++) {
			scanf("%d", &a[i]);
		}
		sort(a, a+n);
		printf("%d\n", a[n/2]);
	}
} 

POJ2388-Who's in the Middle的更多相关文章

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

    G - Who's in the Middle Crawling in process... Crawling failed Time Limit:1000MS     Memory Limit:32 ...

  2. 代码的坏味道(21)——中间人(Middle Man)

    坏味道--中间人(Middle Man) 特征 如果一个类的作用仅仅是指向另一个类的委托,为什么要存在呢? 问题原因 对象的基本特征之一就是封装:对外部世界隐藏其内部细节.封装往往伴随委托.但是人们可 ...

  3. 【BZOJ-2653】middle 可持久化线段树 + 二分

    2653: middle Time Limit: 20 Sec  Memory Limit: 512 MBSubmit: 1298  Solved: 734[Submit][Status][Discu ...

  4. Who's in the Middle[HDU1157]

    Who's in the Middle Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Othe ...

  5. [LintCode] Delete Node in the Middle of Singly Linked List 在单链表的中间删除节点

    Implement an algorithm to delete a node in the middle of a singly linked list, given only access to ...

  6. vertical-align:middle

    img style="vertical-align:middle;" src="<%=basePath%>/images/ckpy.png" > ...

  7. 【leetcode】Sort List (middle)

    Sort a linked list in O(n log n) time using constant space complexity. 思路: 用归并排序.设输入链表为S,则先将其拆分为前半部分 ...

  8. 【leetcode】Reorder List (middle)

    Given a singly linked list L: L0→L1→…→Ln-1→Ln,reorder it to: L0→Ln→L1→Ln-1→L2→Ln-2→… You must do thi ...

  9. 【leetcode】Number of Islands(middle)

    Given a 2d grid map of '1's (land) and '0's (water), count the number of islands. An island is surro ...

  10. 运用vertical:middle 使得元素垂直居中

    我要垂直居中我要垂直居中我要垂直居中我要垂直居中我要垂直居中垂直居中垂直居中垂直居中中垂直居中垂直居中   <!-- 第一步:主题元素display:inline-block;第二步:插入辅助元 ...

随机推荐

  1. 2018-06-07 RF test 1 :TX Power test

    Test item: 1.Output power:   屏蔽网房-同轴线-频谱仪 The radio circuitry, generally referred to as the Device U ...

  2. python TypeError: 'NoneType' object is not iterable

    list(set(map(lambda tp_id : tp_id if not ('#' in tp_id) and len(tp_id.strip().replace('\n', '')) > ...

  3. I.MX6 FFmpeg 录制视频

    /************************************************************************* * I.MX6 FFmpeg 录制视频 * 说明: ...

  4. Uva10366

    模拟乱搞 要说算法的话...乱搞算法? #include<iostream> #include<cstring> #include<algorithm> #incl ...

  5. 【VisualStudio】软件安装中出现的问题

    针对2017版本安装 1. 安装windows通用平台工具出错 报错信息:15605 FQ安装. 2.  LINK : fatal error LNK1104: 无法打开文件“gdi32.lib” 在 ...

  6. Trilead,SSH2的Java调用

    最近项目要部署10台设备,如果每台设备都手动进行部署想想也是醉了. 因为之前一直使用SecurityFX以及SecurityCRT,所以考虑是否可以使用基于SSH2的类库来实现文件拷贝以及远程命令调用 ...

  7. mysql--事务demo1----

    package com.etc.entity; import java.sql.Connection; import java.sql.PreparedStatement; import java.s ...

  8. ES6学习之装饰器

    定义:修饰器是一个对类进行处理的函数,用来修改类的行为 <注>:装饰器只能用来修改类及类的方法 类的装饰: 静态属性:只能通过类访问,修饰函数直接在类上操作 @testable class ...

  9. wdatePicker时间控件的使用

    wdatePicker时间控件的使用 1.引用wdatePicker控件的js <seript src="../../js/My97DatePicker/wdatePicker.js& ...

  10. python超大数计算

    In [26]: %time a = 6789**100000CPU times: user 0 ns, sys: 0 ns, total: 0 nsWall time: 6.2 µsIn [27]: ...