codeforces710B
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.
Input
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.
Output
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.
Example
4
1 2 3 4
2 sol:就是找个中位数,分奇偶讨论即可
#include <bits/stdc++.h>
using namespace std;
typedef int ll;
inline ll read()
{
ll s=;
bool f=;
char ch=' ';
while(!isdigit(ch))
{
f|=(ch=='-'); ch=getchar();
}
while(isdigit(ch))
{
s=(s<<)+(s<<)+(ch^); ch=getchar();
}
return (f)?(-s):(s);
}
#define R(x) x=read()
inline void write(ll x)
{
if(x<)
{
putchar('-'); x=-x;
}
if(x<)
{
putchar(x+''); return;
}
write(x/);
putchar((x%)+'');
return;
}
#define W(x) write(x),putchar(' ')
#define Wl(x) write(x),putchar('\n')
const int N=;
int n,A[N];
int main()
{
int i;
R(n);
for(i=;i<=n;i++) R(A[i]);
sort(A+,A+n+);
if(n&) Wl(A[(n+)>>]);
else Wl(A[n>>]);
return ;
}
/*
input
4
1 2 3 4
output
2
*/
codeforces710B的更多相关文章
随机推荐
- ASP 基础一 网站开发 初步认识
一 .ASP 与 ASP.NET的区别 i.ASP是解释型的动态语言,asp文件包含了前端和动态语言VBScript,来实现对服务器的交互,运行在IIS.PWS等WEB服务器上 II.ASP.NET是 ...
- 【Codeforces 710F】String Set Queries
Codeforces 710 F 思路:KMP学的还是不过关啊... 按照字符串的长度分类,如果长度大于\(\sqrt{n}\)的就扔到什么地方等待查询,否则就扔进trie里面. 对于查询,我们先在t ...
- nfs原理及安装配置
一.简介 二.工作原理 三.安装配置 一.简介 NFS(Network File System)即网络文件系统,它允许网络中的计算机之间通过网络共享资源.将NFS主机分享的目录,挂载到本地客户端当中, ...
- GitHub Git 简单操作
一.使用git更新GitHub 准备:本地已经安装好git 登录GitHub,选择好仓库,点击 Clone or download 拷贝地址 这里的地址为:https://github.com/edw ...
- IDC Digital Transition Annual Festival(2018.10.19)
时间:2018.10.19地点:北京万达文化酒店
- Part 5:Django测试--Django从入门到精通系列教程
该系列教程系个人原创,并完整发布在个人官网刘江的博客和教程 所有转载本文者,需在顶部显著位置注明原作者及www.liujiangblog.com官网地址. 本节将简要介绍Django的自动化测试相关内 ...
- Python高阶函数--map
map()函数 map()是 Python 内置的高阶函数,它接收一个函数 f 和一个 list,并通过把list 的每个元素依次作用在函数 f 上,得到一个新的 list 并返回. 例如,对于lis ...
- 百度之星-1002-list应用
用stl的list即可,注意...代码的简洁性(被debug伤痛)注意合并时可以手动pop,或者用splice进行合并,不能用merge!!!merge合并是自带排序!!! #include<b ...
- 【课程总结】Linux内核分析课程总结
程涵 原创博客 <Linux内核分析>MOOC课程http://mooc.study.163.com/course/USTC-1000029000 每周实验报告: 反汇编一个简单的C程序 ...
- Liinux 学习心得
Linux 内核学习心得 姬梦馨 原创作品 <Linux内核分析>MOOC课程http://mooc.study.163.com/course/USTC-1000029000 反汇编一个简 ...