[Educational Codeforces Round 16]B. Optimal Point on a Line

试题描述

You are given n points on a line with their coordinates xi. Find the point x so the sum of distances to the given points is minimal.

输入

The first line contains integer n (1 ≤ n ≤ 3·105) — the number of points on the line.

The second line contains n integers xi ( - 109 ≤ xi ≤ 109) — the coordinates of the given n points.

输出

Print the only integer x — the position of the optimal point on the line. If there are several optimal points print the position of the leftmost one. It is guaranteed that the answer is always the integer.

输入示例

   

输出示例


数据规模及约定

见“输入

题解

排序输出中位数。

#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <stack>
#include <vector>
#include <queue>
#include <cstring>
#include <string>
#include <map>
#include <set>
using namespace std; const int BufferSize = 1 << 16;
char buffer[BufferSize], *Head, *Tail;
inline char Getchar() {
if(Head == Tail) {
int l = fread(buffer, 1, BufferSize, stdin);
Tail = (Head = buffer) + l;
}
return *Head++;
}
int read() {
int x = 0, f = 1; char c = getchar();
while(!isdigit(c)){ if(c == '-') f = -1; c = getchar(); }
while(isdigit(c)){ x = x * 10 + c - '0'; c = getchar(); }
return x * f;
} #define maxn 300010
int n, A[maxn]; int main() {
n = read();
for(int i = 1; i <= n; i++) A[i] = read(); sort(A + 1, A + n + 1); if(n & 1) printf("%d\n", A[(n>>1)+1]);
else printf("%d\n", A[n>>1]); return 0;
}

[Educational Codeforces Round 16]B. Optimal Point on a Line的更多相关文章

  1. [Educational Codeforces Round 16]E. Generate a String

    [Educational Codeforces Round 16]E. Generate a String 试题描述 zscoder wants to generate an input file f ...

  2. [Educational Codeforces Round 16]D. Two Arithmetic Progressions

    [Educational Codeforces Round 16]D. Two Arithmetic Progressions 试题描述 You are given two arithmetic pr ...

  3. [Educational Codeforces Round 16]C. Magic Odd Square

    [Educational Codeforces Round 16]C. Magic Odd Square 试题描述 Find an n × n matrix with different number ...

  4. [Educational Codeforces Round 16]A. King Moves

    [Educational Codeforces Round 16]A. King Moves 试题描述 The only king stands on the standard chess board ...

  5. Educational Codeforces Round 16

    A. King Moves water.= =. #include <cstdio> ,,,,,-,-,-}; ,-,,,-,,,-,}; #define judge(x,y) x > ...

  6. Educational Codeforces Round 16 B

    Description You are given n points on a line with their coordinates xi. Find the point x so the sum ...

  7. 「暑期训练」「Brute Force」 Optimal Point on a Line (Educational Codeforces Round 16, B)

    题意 You are given n points on a line with their coordinates $x_i$. Find the point x so the sum of dis ...

  8. Educational Codeforces Round 7 D. Optimal Number Permutation 构造题

    D. Optimal Number Permutation 题目连接: http://www.codeforces.com/contest/622/problem/D Description You ...

  9. Educational Codeforces Round 16 E. Generate a String dp

    题目链接: http://codeforces.com/problemset/problem/710/E E. Generate a String time limit per test 2 seco ...

随机推荐

  1. Struts-1和2的比较

    Struts1和Struts2都是MVC设计模式的经典应用框架,下文从代码,性能,测试,功能等方面对Struts1和Struts2进行简单比较,来看看Struts的高级版本在哪些方面进行了优化. (1 ...

  2. Spring-dispatcherServlet

    对于分析SpringMVC,其实就是遵循Servlet世界里最简单的法则“init-service-destroy”. 对于分析SpringMVC的初始化流程,就是分析DispatcherServle ...

  3. Java编程思想学习(十四) 枚举

    关键字enum可以将一组具名的值有限集合创建一种为新的类型,而这些具名的值可以作为常规的程序组件使用. 基本enum特性 调用enum的values()方法可以遍历enum实例,values()方法返 ...

  4. BZOJ-2756 奇怪的游戏 黑白染色+最大流+当前弧优化+二分判断+分类讨论

    这个题的数据,太卡了,TLE了两晚上,各种调试优化,各种蛋疼. 2756: [SCOI2012]奇怪的游戏 Time Limit: 40 Sec Memory Limit: 128 MB Submit ...

  5. 配置hibernate

    http://blog.csdn.net/hanjiancanxue_liu/article/details/9966423

  6. 桂电在linux环境下使用出校器

    一.官方出校器(无界面) 由于学校官方最新的linux版出校器无效,我们只能使用老版本的出校器了. 但因为老版本的出校器是32位的,而现在主流使用的是64位系统,因此我们得安装32位库. 在ubunt ...

  7. IOS基础之 (十五)知识点

    一 SEL 1. 方法的存储位置 每个类的方法地址列表都存储在类对象中. 每个方法都有一个与之对应的SEL类型的对象. 根据一个SEL对象就可以找到方法的地址,进而调用方法. Person.h #im ...

  8. tomcat8编码

    web工程,本机能跑的代码放到生产环境中后能跑但是得不到预期的结果,十有八九的原因是 编码问题

  9. 转载大神的检测网站重定向的python脚本

    #!/usr/bin/env python #coding=utf8 import sys import requests def check_for_redirects(url): try: r = ...

  10. 安装hadoop2.4.0遇到的问题

    一.执行start-dfs.sh后,datenode没有启动 查看日志如下: 2014-06-18 20:34:59,622 FATAL org.apache.hadoop.hdfs.server.d ...