1753: [Usaco2005 qua]Who's in the Middle

Time Limit: 5 Sec  Memory Limit: 64 MB
Submit: 290  Solved: 242
[Submit][Status][Discuss]

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. 输入N个数,输出升序排列后中间那个数.

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

INPUT DETAILS:

Five cows with milk outputs of 1..5

Sample Output

3

OUTPUT DETAILS:

1 and 2 are below 3; 4 and 5 are above 3.

HINT

 

Source

Gold

题解:难以想象这样的题目居然是usaco金组的= =,汗。。

其实直接排序就好啦,但是这样子太没意思了,于是来个简单的小优化(程序如下,很清晰,相信你们一定看得懂)

 /**************************************************************
Problem:
User: HansBug
Language: Pascal
Result: Accepted
Time: ms
Memory: kb
****************************************************************/ var
i,j,k,l,m,n,x,y:longint;
a:array[..] of longint;
procedure sort(l,r:longint);
var i,j,x,y:longint;
begin
if (l>m) or (r<m) then exit; //here!!!^_^
i:=l;j:=r;x:=a[(l+r) div ];
repeat
while a[i]<x do inc(i);
while a[j]>x do dec(j);
if i<=j then
begin
y:=a[i];a[i]:=a[j];a[j]:=y;
inc(i);dec(j);
end;
until i>j;
if i<r then sort(i,r);
if l<j then sort(l,j);
end; begin
readln(n);m:=(+n) div ;
for i:= to n do readln(a[i]);
sort(,n);
writeln(a[m]);
readln;
end.

1753: [Usaco2005 qua]Who's in the Middle的更多相关文章

  1. bzoj 1753: [Usaco2005 qua]Who's in the Middle【排序】

    --这可能是早年Pascal盛行的时候考排序的吧居然还是Glod-- #include<iostream> #include<cstdio> #include<algor ...

  2. bzoj1753 [Usaco2005 qua]Who's in the Middle

    Description FJ is surveying his herd to find the most average cow. He wants to know how much milk th ...

  3. BZOJ1754: [Usaco2005 qua]Bull Math

    1754: [Usaco2005 qua]Bull Math Time Limit: 5 Sec  Memory Limit: 64 MBSubmit: 374  Solved: 227[Submit ...

  4. bzoj1751 [Usaco2005 qua]Lake Counting

    1751: [Usaco2005 qua]Lake Counting Time Limit: 5 Sec  Memory Limit: 64 MB Submit: 168  Solved: 130 [ ...

  5. 1755: [Usaco2005 qua]Bank Interest

    1755: [Usaco2005 qua]Bank Interest Time Limit: 5 Sec  Memory Limit: 64 MBSubmit: 187  Solved: 162[Su ...

  6. 1754: [Usaco2005 qua]Bull Math

    1754: [Usaco2005 qua]Bull Math Time Limit: 5 Sec  Memory Limit: 64 MBSubmit: 398  Solved: 242[Submit ...

  7. 1751: [Usaco2005 qua]Lake Counting

    1751: [Usaco2005 qua]Lake Counting Time Limit: 5 Sec  Memory Limit: 64 MBSubmit: 190  Solved: 150[Su ...

  8. bzoj3384[Usaco2004 Nov]Apple Catching 接苹果*&&bzoj1750[Usaco2005 qua]Apple Catching*

    bzoj3384[Usaco2004 Nov]Apple Catching 接苹果 bzoj1750[Usaco2005 qua]Apple Catching 题意: 两棵树,每分钟会从其中一棵树上掉 ...

  9. BZOJ 1754: [Usaco2005 qua]Bull Math

    Description Bulls are so much better at math than the cows. They can multiply huge integers together ...

随机推荐

  1. Google Analytics之增强型电子商务报告

    虽然Google Analytics很多年以前就提供了电子商务报告的功能,但对于电子商务网站来说,这个报告缺失的东西还太多.而Google Analytics即将推出的增强型电子商务报告有望弥补这一短 ...

  2. SQL查询根节点

    /* 标题:查询指定节点及其所有父节点的函数 作者:爱新觉罗.毓华(十八年风雨,守得冰山雪莲花开) 时间:2008-05-12 地点:广东深圳 */ create table tb(id varcha ...

  3. DNS信息

    主机A记录: 描述主机地址记录,在dns域名和ip地址之间建立映射关系语法: owner class ttl A IP_v4_address eg: host1.example.mircrosoft. ...

  4. jQuery插入节点(移动节点)

    jQuery插入节点(移动节点) <%@ page language="java" import="java.util.*" pageEncoding=& ...

  5. HDU1173

    采矿 Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submiss ...

  6. HDU5882

    Balanced Game Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Tot ...

  7. 微信小程序教程(第二篇)

    如何注册接入小程序及搭建开发环境 小程序接入流程 注册 主要分为注册邮箱与信息登记. 需要重新申请一个新的微信公众帐号,不能使用服务号.订阅号或企业号使用的公众帐号 (微信公众帐号分为四种类型:订阅号 ...

  8. CI Weekly #13 | 用更 Geek 的方式配置你的 CI 工作流

    flow.ci 的重大更新来了--支持通过 .yml 文件配置工作流(测试阶段),具体的使用方法可参考文档:同时 flow.ci 也开放了社区>> club.flow.ci,使用的任何问题 ...

  9. CoreCLR源码探索(三) GC内存分配器的内部实现

    在前一篇中我讲解了new是怎么工作的, 但是却一笔跳过了内存分配相关的部分. 在这一篇中我将详细讲解GC内存分配器的内部实现. 在看这一篇之前请必须先看完微软BOTR文档中的"Garbage ...

  10. Extjs学习笔记之九 数据模型(上)-extjs

    来源:niutuku.com | vincent上传于2012-07-20 | 1802次浏览 | 0条评论 本文开始进入Extjs最核心最优秀的部分. 标签:Extjs 数据模型   Extjs的数 ...