Who's in the Middle
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
* Lines 2..N+1: Each line contains a single integer that is the milk output of one cow.
Output
5 2 4 1 3 5
Sample Output
3
Hint
Five cows with milk outputs of 1..5
OUTPUT DETAILS:
1 and 2 are below 3; 4 and 5 are above 3.
#include <iostream>
using namespace std;
int main( )
{
int num;
int arr[1001];
while(cin>>num)
{
int i,temp,counter=0;
for(i=0;i<1001;i++)
arr[i]=0;
for(i=0;i<num;i++)
{
cin>>temp;
arr[temp]++;
}
for(i=1;i<=1000;i++)
{
for(temp=1;temp<=1000;temp++)
{
if(arr[temp]!=0)
{
arr[temp]--;
break;
}
}
for(temp++;temp<=1000;temp++)
{
if(arr[temp]!=0)
{
arr[temp]--;
counter++;
}
}
}
cout<<counter<<endl;
}
return 0;
}
Who's in the Middle的更多相关文章
- 代码的坏味道(21)——中间人(Middle Man)
坏味道--中间人(Middle Man) 特征 如果一个类的作用仅仅是指向另一个类的委托,为什么要存在呢? 问题原因 对象的基本特征之一就是封装:对外部世界隐藏其内部细节.封装往往伴随委托.但是人们可 ...
- 【BZOJ-2653】middle 可持久化线段树 + 二分
2653: middle Time Limit: 20 Sec Memory Limit: 512 MBSubmit: 1298 Solved: 734[Submit][Status][Discu ...
- 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 ...
- [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 ...
- vertical-align:middle
img style="vertical-align:middle;" src="<%=basePath%>/images/ckpy.png" > ...
- 【leetcode】Sort List (middle)
Sort a linked list in O(n log n) time using constant space complexity. 思路: 用归并排序.设输入链表为S,则先将其拆分为前半部分 ...
- 【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 ...
- 【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 ...
- 运用vertical:middle 使得元素垂直居中
我要垂直居中我要垂直居中我要垂直居中我要垂直居中我要垂直居中垂直居中垂直居中垂直居中中垂直居中垂直居中 <!-- 第一步:主题元素display:inline-block;第二步:插入辅助元 ...
- Who's in the Middle 分类: POJ 2015-06-12 19:45 11人阅读 评论(0) 收藏
Who's in the Middle Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 34155 Accepted: 1 ...
随机推荐
- 《Linux命令行与shell脚本编程大全》第十五章 呈现数据
15.1 理解输入和输出 现在知道两种显示脚本输出的方法 1)在显示器屏幕上显示 2)将输出文件重定向到文件中 15.1.1 标准文件描述符 Linux系统将每个对象当做文件处理.这包括输入和数出进程 ...
- asp.net core 实现一个简单的仓储
一直有自己写个框架的想法,但是一直没有行动起来,最近比较闲,正好可以开工了. 现在已经完成了两部分.1.一个简单仓储,实现使用的是ef 2.IOC部分,这里是把内置的ioc替换成了aotofac,这部 ...
- ABAP 7.52 中的Open SQL新特性
S/4 HANA 1709 已经在几个月前发布,随之而来的是ABAP 7.52. 本文翻译了更新文档中有关Open SQL的部分 本文链接:http://www.cnblogs.com/hhelibe ...
- 网页的居中显示,使用了margin、clear:both
很久没写过页面了,现在写起来也觉得捡起来还是挺快的. 当时遇到了这样的问题,我有一个大的div包涵了整个网站,有网页头部,中部还有底部.头部就是一个标题,中部就是几张图片跟文字排版,结果左右两边的图片 ...
- selenium+python对页面元素进行高亮显示
调用js方法: execute_script(script,*args) Arguments对象: 类数组对象,代表传给一个function的参数列表,当前函数的内置属性,其长度是由实参个数决定而不是 ...
- 自己动手编写IOC框架(三)
刚写博客浏览量第一天就有1000多人次,给了我很大的鼓舞决定熬夜再写一篇.对于前两篇来说无非就是使用dtd验证xml,然后解析xml,和IOC的核心还是差的很远,相信很多小伙伴们都感觉看得不过瘾了,这 ...
- String、StringBuilder和StringBuffer
1.string不可变性 java的docs有这样一句话:Strings are constant; their values cannot be changed after they are cre ...
- iOS中常见的锁
多线程的安全隐患 一块资源可能会被多个线程共享,也就是说多个线程可能会访问同一块资源. 比如多个线程同时操作同一个对象,同一个变量. 当多个线程访问同一块资源时,很容易引发数据错乱和数据安全问题. 比 ...
- TempFile模块
tempfile模块,用来对临时数据进行操作 tempfile 临时文件(夹)操作 tempfile.mkstemp([suffix="[, prefix='tmp'[, dir=None[ ...
- 虚拟DOM详解
虚拟DOM简介 Virtual Dom可以看做一棵模拟了DOM树的JavaScript对象树,其主要是通过vnode,实现一个无状态的组件,当组件状态发生更新时,然后触发Virtual Dom数据的变 ...