[Educational Codeforces Round 16]B. Optimal Point on a Line
[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.
输出
输入示例
输出示例
数据规模及约定
见“输入”
题解
排序输出中位数。
#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的更多相关文章
- [Educational Codeforces Round 16]E. Generate a String
[Educational Codeforces Round 16]E. Generate a String 试题描述 zscoder wants to generate an input file f ...
- [Educational Codeforces Round 16]D. Two Arithmetic Progressions
[Educational Codeforces Round 16]D. Two Arithmetic Progressions 试题描述 You are given two arithmetic pr ...
- [Educational Codeforces Round 16]C. Magic Odd Square
[Educational Codeforces Round 16]C. Magic Odd Square 试题描述 Find an n × n matrix with different number ...
- [Educational Codeforces Round 16]A. King Moves
[Educational Codeforces Round 16]A. King Moves 试题描述 The only king stands on the standard chess board ...
- Educational Codeforces Round 16
A. King Moves water.= =. #include <cstdio> ,,,,,-,-,-}; ,-,,,-,,,-,}; #define judge(x,y) x > ...
- 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 ...
- 「暑期训练」「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 ...
- Educational Codeforces Round 7 D. Optimal Number Permutation 构造题
D. Optimal Number Permutation 题目连接: http://www.codeforces.com/contest/622/problem/D Description You ...
- 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 ...
随机推荐
- OpenCart 最新使用教学视频合集
OpenCart 是一个很火的开源电商系统,国内越来越多的人开始使用 OpenCart 搭建自己的电商网站.OpenCart 的功能非常强大,当然功能也非常多.这里整理了 OpenCart 最重要的一 ...
- 【BZOJ1013】【JSOI2008】球形空间产生器sphere(高斯消元)
1013: [JSOI2008]球形空间产生器sphere Time Limit: 1 Sec Memory Limit: 162 MBSubmit: 1600 Solved: 860[Submi ...
- 编写高质量代码改善C#程序的157个建议[用抛异常替代返回错误、不要在不恰当的场合下引发异常、重新引发异常时使用inner Exception]
前言 自从.NET出现后,关于CLR异常机制的讨论就几乎从未停止过.迄今为止,CLR异常机制让人关注最多的一点就是“效率”问题.其实,这里存在认识上的误区,因为正常控制流程下的代码运行并不会出现问题, ...
- 关闭浏览器后Session失效原因分析
参考文章:http://www.tuicool.com/articles/VNbYjqm 首先需要理解一下几点: 1.Http是无状态的,即对于每一次请求都是一个全新的请求,服务器不保存上一次请求的信 ...
- Java基础-关键字-final
在Java中,final关键字可以用来修饰类.方法和变量(包括成员变量和局部变量).下面就从这三个方面来了解一下final关键字的基本用法. 1.修饰类 当用final修饰一个类时,表明这个类不能被继 ...
- python 学习笔记2(list/directory/文件对象/模块/参数传递)
### Python的强大很大一部分原因在于,它提供有很多已经写好的,可以现成用的对象. 11. list list是一个类.每个列表都属于该类. >>>nl = [1,2,5,3, ...
- Java编程思想学习(二) 操作符
1. 对象“赋值”:对一个对象进行操作时,我们真正操作的是对对象的引用.所以倘若“将一个对象赋值给另一个对象”,实际是将“引用”从一个地方复制到另一个地方.(引用于对象之间存在关联,但这种关联可以被改 ...
- 7.Android之评分条RatingBar和拖动条SeekBar学习
评分条RatingBar和拖动条SeekBar很常见,今天来学习下. (1)RatingBar评分条 如图: <RelativeLayout xmlns:android="http:/ ...
- 人工免疫算法-python实现
AIAIndividual.py import numpy as np import ObjFunction class AIAIndividual: ''' individual of artifi ...
- POJ1011 Sticks
Description George took sticks of the same length and cut them randomly until all parts became at mo ...