HDU1157 Who's in the Middle
Who's in the Middle
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.
* Lines 2..N+1: Each line contains a single integer that is the milk output of one cow.
5
2
4
1
3
5
3HintINPUT DETAILS: Five cows with milk outputs of 1..5 OUTPUT DETAILS: 1 and 2 are below 3; 4 and 5 are above 3.
水水水
#include <stdio.h>
#include <algorithm>
using std::sort;
#define maxn 10002 int arr[maxn]; int main()
{
int n, i;
while(scanf("%d", &n) == 1){
for(i = 0; i < n; ++i)
scanf("%d", &arr[i]);
sort(arr, arr + n);
printf("%d\n", arr[(n-1) >> 1]);
}
return 0;
}
HDU1157 Who's in the Middle的更多相关文章
- poj 2388 Who's in the Middle
Who's in the Middle Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 31149 Accepted: 1 ...
- POJ 2388:Who's in the Middle
Who's in the Middle Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 31015 Accepted: 1 ...
- 2388 Who's in the Middle(简单排序)
训练计划的第一个问题,首先从水问题开始:排序的数组,中间数则输出. http://poj.org/problem?id=2388 冒泡排序: #include <iostream> usi ...
- 02python程序设计基础——字符串
字符串方法 format 1.替换字段名 在最简单的情况下,只需向 format 提供要设置其格式的未命名参数,并在格式字符串中使用未命名字段.此时,将按顺序将字段和参数配对.你还可给参数指定名称,这 ...
- 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 ...
- 基于C#的BarCode 39实现
一.39条码简介 39码是1974年发展出来的条码系统,是一种可供使用者双向扫瞄的分散式条码,也就是说相临两资料码之间,必须包含一个不具任何意义的空白(或细白,其逻辑值为0),且其具有支援文字的能力, ...
- 圣思源Java视频36节练习源码分享(自己的190+行代码对比老师的39行代码)
题目: * 随机生成50个数字(整数),每个数字范围是[10,50],统计每个数字出现的次数 * 以及出现次数最多的数字与它的个数,最后将每个数字及其出现次数打印出来, * 如果某个数字出现次数为0, ...
- 剑指Offer:数组中出现次数超过一半的数字【39】
剑指Offer:数组中出现次数超过一半的数字[39] 题目描述 数组中有一个数字出现的次数超过数组长度的一半,请找出这个数字.例如,输入一个长度为9的数组{1,2,3,2,2,2,5,4,2}.由于这 ...
- 【转】39个让你受益的HTML5教程
闲话少说,本文作者为大家收集了网上学习HTML5的资源,期望它们可以帮助大家更好地学习HTML5. 好人啊! 不过,作者原来说的40个只有39个,因为第5个和第8个是重复的. 原文在此! 1. 五分钟 ...
随机推荐
- python变现实现新浪微博登陆
新浪微博的登陆现在是越来越那个了,以前的模拟浏览器登陆新浪微博貌似也越来不管用了 登陆信息由以前的form变成了现在javascript,javascript的加载居然用了一个javascript的函 ...
- KVM(六)Nova 通过 libvirt 管理 QEMU/KVM 虚机
1. Libvirt 在 OpenStack 架构中的位置 在 Nova Compute 节点上运行的 nova-compute 服务调用 Hypervisor API 去管理运行在该 Hypervi ...
- 拒绝平庸——浅谈WEB登录页面设计
用户活跃度是检验产品成功与否的重要指标之一,传统行业的商家极为重视门面的装潢,因为一个好的门面可以聚集人气,招揽更多的顾客.古时候的大户人家院子门口的石狮子或其他的摆件的摆放极为讲究,有一定的风水学说 ...
- ionic3 关于屏幕方向问题
关于屏幕方向问题 使用ionic-native中的screen-orientation ionic cordova plugin add cordova-plugin-screen-orientati ...
- HDU 多校1.4
Division Game Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Others) ...
- linux历史命令
"忘记历史的Linux用户注定要输入很多信息.” 这也让强有力的历史命令(包括Bash shell的历史变体)不仅在援引之前执行命令而不需重新输入它们时有用,在调用其它很少用到的命令时也有用 ...
- python requests的安装与简单运用(转)
http://www.cnblogs.com/fightformylife/p/4134986.html http://cn.python-requests.org/zh_CN/latest/ htt ...
- [BZOJ1790][AHOI2008]Rectangle 矩形藏宝地(四维偏序,CDQ+线段树)
1790: [Ahoi2008]Rectangle 矩形藏宝地 Time Limit: 10 Sec Memory Limit: 64 MBSubmit: 553 Solved: 193[Subm ...
- 【二分图判定】hdu3478 Catch
详细的题解:http://www.docin.com/p-517243379.html 一个图是二分图 等价于 其至少有两个节点且没有奇环. 二分图判定的方法:从任意点出发进行一次dfs黑白染色,若某 ...
- Problem R: 零起点学算法13——求2个时间之间的分钟数
#include<stdio.h> int main() { int a1,b1,a2,b2,s; scanf("%d:%d",&a1,&b1); sc ...