POJ 2388:Who's in the Middle
Time Limit: 1000MS | Memory Limit: 65536K | |
Total Submissions: 31015 | Accepted: 17991 |
Description
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
Sample Input
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<cstdio>
#include<stdlib.h>
#include<cstring>
#include<algorithm>
#include<iostream> using namespace std; const int M = 10000 + 5;
int cow[M]; int main()
{
int n;
while(scanf("%d", &n)!=EOF)
{
memset(cow, 0, sizeof(cow));
for(int i=0; i<n; i++)
scanf("%d", &cow[i]);
sort(cow, cow+n);
printf("%d\n", cow[n/2]);
} return 0;
}
POJ 2388:Who's in the Middle的更多相关文章
- poj 2388 insert sorting
/** \brief poj 2388 insert sorting 2015 6 12 * * \param * \param * \return * */ #include <iostrea ...
- POJ 3321:Apple Tree + HDU 3887:Counting Offspring(DFS序+树状数组)
http://poj.org/problem?id=3321 http://acm.hdu.edu.cn/showproblem.php?pid=3887 POJ 3321: 题意:给出一棵根节点为1 ...
- POJ 3252:Round Numbers
POJ 3252:Round Numbers Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 10099 Accepted: 36 ...
- Ultra-QuickSort 分类: POJ 排序 2015-08-03 15:39 2人阅读 评论(0) 收藏
Ultra-QuickSort Time Limit: 7000MS Memory Limit: 65536K Total Submissions: 48111 Accepted: 17549 ...
- POJ 2965:The Pilots Brothers' refrigerator
id=2965">The Pilots Brothers' refrigerator Time Limit: 1000MS Memory Limit: 65536K Total S ...
- POJ 2388 Who's in the Middle (快速选择算法:O(N)求数列第K大)
[题意]求数列中间项. ---这里可以扩展到数列第K项. 第一次做的时候直接排序水过了= =--这一次回头来学O(N)的快速选择算法. 快速选择算法基于快速排序的过程,每个阶段我们选择一个数为基准,并 ...
- 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(水~奇数个数排序求中位数)
题目链接:http://poj.org/problem?id=2388 题目大意: 奇数个数排序求中位数 解题思路:看代码吧! AC Code: #include<stdio.h> #in ...
- POJ 2388(排序)
http://poj.org/problem?id=2388 题意:就N个数的中位数. 思路:用快排就行了.但我没用快排,我自己写了一个堆来做这个题.主要还是因为堆不怎么会,这个拿来练练手. #inc ...
随机推荐
- 【CF1016F】Road Projects(贪心)
题意:给你一棵n 个节点的树,定义1到n的代价是1到 n节点间的最短路径的长度. 现在给你 m 组询问,让你添加一条边权为 w 的边(不与原图重复),求代价的最大值.询问之间相互独立. 1≤n,m≤3 ...
- QT5.3 杂记(转)
原文转自 https://www.cnblogs.com/aoldman/p/3968280.html Qt5下,QWidget系列从QtGui中被剥离出去,成为单独的QtWidget模块.随着Qt ...
- Linux的日志错误级别
讯息等级 系统将讯息分为七个主要的等级,依序是由不重要排列到重要讯息等级: info:仅是一些基本的讯息说明而已: notice:比 info 还需要被注意到的一些信息内容: warning 或 wa ...
- CppCMS1.0.3 Build by VS2012
1.CppCMS简介 CppCMS是一个C++的Web开发框架(不是一个CMS).它不同于大多数其他Web开发框架,如巨蟒Django , Java的Servlets ,或C++ Wt因为它在设计和调 ...
- Android 中带有进度条效果的按钮(Button)
安卓中带有进度条效果的按钮,如下图: 1.布局文件如下activity_main.xml <RelativeLayout xmlns:android="http://schemas.a ...
- 【原创】SSAS-引用维度与多数据源、多数据源视图引发分区错误
背景: 最近有个项目,有32家分公司,集团总部需要取这个32家分公司数据做分析,由于每个分公司的数据都比较庞大,所以最终方案是每个分公司一个DW,在cube搭建过程中将每个公司数据作为一个分区数据的来 ...
- Codeforces 940F Machine Learning (带修改莫队)
题目链接 Codeforces Round #466 (Div. 2) Problem F 题意 给定一列数和若干个询问,每一次询问要求集合$\left\{c_{0}, c_{1}, c_{2}, ...
- Python的Web编程[0] -> Web客户端[0] -> 统一资源定位符 URL
统一资源定位符 / URL 目录 URL 构成 URL 解析 URL 处理 1 URL构成 统一资源定位符(Uniform Resource Locator) 是对可以从互联网上得到的资源的位置和访问 ...
- 牛客nowcoder Noip提高组第四场
https://www.nowcoder.com/acm/contest/175#question A-动态点分治 Description CJK 是一个喜欢数据结构的同学.一天他看到 BZOJ 40 ...
- UTF-8 setup for workspace
In Eclipse, go to Preferences>General>Workspace and select UTF-8 as the Text File Encoding. Th ...