Educational Codeforces Round 16 B. Optimal Point on a Line【水】
来源:互联网 发布:pss监控软件下载 编辑:程序博客网 时间:2024/06/04 19:11
B. Optimal Point on a Line
time limit per test
1 secondmemory limit per test
256 megabytesinput
standard inputoutput
standard outputYou 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
41 2 3 4
output
2
原题链接:http://codeforces.com/contest/710/problem/B
题意:给你一些在X轴上的点,让你找一点,使其到其它所有点的距离之和最小。
好像和HDU11页上有一题好像。
AC代码:
#include <bits/stdc++.h>using namespace std ;const int maxn=int(3*1e5)+5;int a[maxn];int main(){ int n; ios::sync_with_stdio(false); //freopen("B.txt","r",stdin); while(cin>>n) { for(int i=0;i<n;i++) cin>>a[i]; sort(a,a+n); cout<<a[(n-1)/2]<<endl; } return 0;}
尊重原创,转载请注明出处:http://blog.csdn.net/hurmishine
0 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】Codeforces 710B 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(中位数)
- 【模拟】Codeforces 710B Optimal Point on a Line
- codeforces 710B - Optimal Point on a Line
- Codeforces 710B-Optimal Point on a Line
- CodeForces-710B. Optimal Point on a Line
- CodeForces 710B Optimal Point on a Line 找中位数
- Codeforces Problem 710B Optimal Point on a Line(距离之和最小)
- 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 1 B.Queries on a String(模拟)
- 【Educational Codeforces Round 1B】【字符串平移 水题】Queries on a String 字符串平移水题
- Educational Codeforces Round 8 (A B C)
- Educational Codeforces Round 17 A+B
- Linux中强大且常用命令:find、grep
- iostream迭代器操作"txt文本文件"无法写入的思考
- poj 2096
- Java虚拟机详解----常用JVM配置参数
- CentOS7配置防火墙
- Educational Codeforces Round 16 B. Optimal Point on a Line【水】
- java List多字段排序
- 一个监督的赫布学习(Hebb Learning)的例子
- Maximal Square
- 56. Merge Intervals 对区间进行合并
- leetcode题解日练--2016.09.03
- 各个 Linux 发行版的风格和哲学分别是怎样的?
- RxJava 基础
- Linux下6种优秀的邮件传输代理