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 ...
随机推荐
- Less 的使用方法
Less 的使用方法 Less 可以直接在浏览器端运行(支持IE6+.Webkit.Firefox),也可以借助Node.js或者Rhino在服务端运行. Less是一种动态语言,无论是在浏览器端,还 ...
- 【ElementUI】日期选择器时间选择范围限制
ElementUI是饿了么推出的一套基于vue2.x的一个ui框架.官方文档也很详细,这里做一个element-ui日期插件的补充. 官方文档中使用picker-options属性来限制可选择的日期, ...
- 用lua+redis实现一个简单的计数器功能 (一)
首先安装环境 依赖环境有 luajit http://luajit.org ngx_devel_kit https://github.com/simpl/ngx_devel_kit echo-ngin ...
- ThinkPHP中ajax绑定select下拉框无法显示
html代码: 控制器代码: 其中的<option value="{$vo.gradeId}">{$one.gradeName}</option> 在操作过 ...
- codeforces 897A Scarborough Fair 暴力签到
codeforces 897A Scarborough Fair 题目链接: http://codeforces.com/problemset/problem/897/A 思路: 暴力大法好 代码: ...
- PHPstorm 如何新增项目
如何在PHPstorm新增项目 1.打开设置 2.找到Directories ,点击增加路径
- OpenCV 读取视频 多种方式
OpenCV中常见的视频方式是while循环读取,可是,当遇到嵌套循环呢 1.常见的while循环 ,没有嵌套循环 cv::VideoCapture capture("d:/test/dem ...
- db2 update 异常
报错: -错误的sql语句:update Persons SET FirstName = 'Fred' WHERE id_P = 1com.ibm.db2.jcc.am.SqlException: O ...
- poj Minimum( CutStoer Wagner算法)
Minimum Cut 题目: 给出一张图.要求你删除最小割权和图. 算法分析: //////////////////// 转载 --- ylfdrib ///////////////// ...
- 为什么说要搞定微服务架构,先搞定RPC框架?
今天开始聊一些微服务的实践,第一块,RPC框架的原理及实践,为什么说要搞定微服务架构,先搞定RPC框架呢? 一.需求缘起 服务化的一个好处就是,不限定服务的提供方使用什么技术选型,能够实现大公司跨团队 ...