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 ...
随机推荐
- static,final,包,访问修饰符,内部类
static 关键字可以修饰成员变量,被static修饰的成员变量归属于类static关键字可以修饰成员方法:被static修饰的成员方法可以直接使用类名调用,也可以通过对象调用,建议使用类名.非静态 ...
- leetcode算法题2: 合并两个二叉树。递归,如何切入并保持清醒?
/* Given two binary trees and imagine that when you put one of them to cover the other, some nodes o ...
- codeforces 895A Pizza Separation 枚举
codeforces 895A Pizza Separation 题目大意: 分成两大部分,使得这两部分的差值最小(注意是圆形,首尾相连) 思路: 分割出来的部分是连续的,开二倍枚举. 注意不要看成0 ...
- 获取串口映射的COM端口号
背景:近期由于项目需要,需要操作短信猫,当短信猫插入电脑后,会根据当前PC状况,映射COM口,这里需动态获取短信猫映射的COM端口号. 编程语言C#: 具体代码如下 public enum Hardw ...
- 删除kafka的topic及kafka基本命令
kafka的topic默认是不允许被删除的,删除后在topic后会出现”marked for deletion”字样,实际并未删除,现在创建同样的topic会提示topic已经存在. 解决办法: se ...
- OAuth 2.0(网转)
(一)背景知识 OAuth 2.0很可能是下一代的"用户验证和授权"标准,目前在国内还没有很靠谱的技术资料.为了弘扬"开放精神",让业内的人更容易理解" ...
- JAVA中静态修饰符static的学习(初学)
静态修饰符static,用于修饰类中的成员变量和成员函数. 用static修饰的成员变量也可叫做类变量. 什么时候使用静态 什么时候定义静态成员变量? 当对象中出现共享数据时,将该数据定义为静 ...
- java学习总结篇一--写在正式成为码农一年后
一直想写一写工作了一年多的总结与感悟,今天正好有时间,也有这个兴致,随手总结一下这一年来学习及工作的情况. 大学时很无奈地被选择了计算机专业,本人对计算机,不讨厌,也算不上多喜欢.只是当惯了好学生,好 ...
- webrtc视频数据解码处理流程
- poj 1318Word Amalgamation
题目链接:http://poj.org/problem?id=1318 /*题意:在字母乱序的单词里面找到字母相同的字典里面的单词*/ /*此题的主要思路是要将字符排序,然后找对应,如果相同,那么就将 ...