POJ2388-Who's in the Middle
题目链接:点击打开链接
Who's in the Middle
| Time Limit: 1000MS | Memory Limit: 65536K | |
| Total Submissions: 45683 | Accepted: 26310 |
Description
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
* Line 1: A single integer N
* Lines 2..N+1: Each line contains a single integer that is the milk output of one cow.
Output
* Line 1: A single integer that is the median milk output.
Sample Input
5
2
4
1
3
5
Sample Output
3
题目大意:找中间数
思路:sort 然后a【n/2】;
AC代码:
#include<cstdio>
#include<iostream>
#include<algorithm>
using namespace std;
int a[10010];
int n;
int main() {
while(~scanf("%d", &n)) {
for(int i = 0; i < n; i++) {
scanf("%d", &a[i]);
}
sort(a, a+n);
printf("%d\n", a[n/2]);
}
}
POJ2388-Who's in the Middle的更多相关文章
- 暑假集训(2)第五弹 ----- Who's in the Middle(poj2388)
G - Who's in the Middle Crawling in process... Crawling failed Time Limit:1000MS Memory Limit:32 ...
- 代码的坏味道(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;第二步:插入辅助元 ...
随机推荐
- leetcode 268 Missing Number(异或运算的应用)
Given an array containing n distinct numbers taken from 0, 1, 2, ..., n, find the one that is missin ...
- Python解决中文字符的问题
from __future__ import unicode_literals print(type("test")) #<type 'unicode'> Chinat ...
- Android学习路线01
part1:Java 1.Java基础 2.Java面向对象 3.数组与集合,异常,常用类 4.Io流 5.多线程socket编程 6.数据库,网络传输,数据解析 part2:Android 1.An ...
- URAL1517Freedom of Choice(后缀数组)
Background Before Albanian people could bear with the freedom of speech (this story is fully describ ...
- hdp 集群问题解决记录
2019-04-23 14:16:21,769 WARN namenode.FSImage (EditLogFileInputStream.java:scanEditLog(359)) - Caugh ...
- python实现redis三种cas事务操作
cas全称是compare and set,是一种典型的事务操作. 简单的说,事务就是为了存取数据库中同一数据时不破坏操作的隔离性和原子性,从而保证数据的一致性. 一般数据库,比如MySql是如何保证 ...
- Poj 1125 Stockbroker Grapevine(Floyd算法求结点对的最短路径问题)
一.Description Stockbrokers are known to overreact to rumours. You have been contracted to develop a ...
- HDOJ5044(最近公共祖先)
#include<cstdio> #include<cstring> using namespace std; ; struct Edge{ int v,id,next; }e ...
- CURL访问举例
<?php function request($url, $params = [], $requestMethod = 'GET', $jsonDecode = true, $headers = ...
- JAVA基础知识总结1(概述)
JAVA概述: 1991 年Sun公司的James Gosling等人开始开发名称为 Oak 的语言,希望用于控制嵌入在有线电视交换盒.PDA等的微处理器. 1994年将Oak语言更名为Java. J ...