Educational Codeforces Round 16 B. Optimal Point on a Line
2016-08-23 14:06
531 查看
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
input
output
最近感觉智商真的捉急啊,好多并不是很难得题就是想不出来,基础部分也要好好练练了
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
input
4 1 2 3 4
output
2
最近感觉智商真的捉急啊,好多并不是很难得题就是想不出来,基础部分也要好好练练了
#include <iostream> #include <cstring> #include <cmath> #include <algorithm> using namespace std; const int maxn=300000; int a[maxn]; int main() { int n; scanf("%d",&n); for(int i=1;i<=n;i++) scanf("%d",&a[i]); sort(a+1,a+n+1); printf("%d\n",a[(n+1)/2]); return 0; }
相关文章推荐
- Educational Codeforces Round 16 B. Optimal Point on a Line(中位数)
- Educational Codeforces Round 16 B. Optimal Point on a Line (水题)
- Educational Codeforces Round 16 B. Optimal Point on a Line【水】
- 【Educational Codeforces Round 16】 Codeforces 710E Generate a String
- codeforces Educational Round 16 E. Generate a String
- Educational Codeforces Round 16 -- C - Magic Odd Square (找规律)
- Educational Codeforces Round 16 E. Generate a String (dp)
- Educational Codeforces Round 16 C. Magic Odd Square
- 【Educational Codeforces Round 16】Codeforces 710B Optimal Point on a Line
- Educational Codeforces Round 1 B. Queries on a String 暴力
- Educational Codeforces Round 1 B. Queries on a String
- Educational Codeforces Round 30 C. Strange Game On Matrix
- Educational Codeforces Round 7 CF622C Not Equal on a Segment
- 【Educational Codeforces Round 1B】【字符串平移 水题】Queries on a String 字符串平移水题
- [Educational Codeforces Round 16]D. Two Arithmetic Progressions ★ ★ ★
- Educational Codeforces Round 16---部分题解
- Educational Codeforces Round 16 (A-E)
- Educational Codeforces Round 16 E. Generate a String-DP
- codeforces Educational Codeforces Round 16-E(DP)
- 【Educational Codeforces Round 16】Codeforces 710C Magic Odd Square