题目链接:

B. Optimal Point on a Line

题意:

给出n个点,问找出一个点使得这个点到所有的点的距离和最小;

思路:

所有点排序后的中位数;这是一个结论;

AC代码:

#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <bits/stdc++.h>
#include <stack>
#include <map> using namespace std; #define For(i,j,n) for(int i=j;i<=n;i++)
#define mst(ss,b) memset(ss,b,sizeof(ss)); typedef long long LL; template<class T> void read(T&num) {
char CH; bool F=false;
for(CH=getchar();CH<'0'||CH>'9';F= CH=='-',CH=getchar());
for(num=0;CH>='0'&&CH<='9';num=num*10+CH-'0',CH=getchar());
F && (num=-num);
}
int stk[70], tp;
template<class T> inline void print(T p) {
if(!p) { puts("0"); return; }
while(p) stk[++ tp] = p%10, p/=10;
while(tp) putchar(stk[tp--] + '0');
putchar('\n');
} const LL mod=1e9+7;
const double PI=acos(-1.0);
const int inf=1e9;
const int N=3e5+10;
const int maxn=1e3+20;
const double eps=1e-12; int x[N]; int main()
{
int n;
read(n);
For(i,1,n)read(x[i]);
sort(x+1,x+n+1);
if(n%2==1)cout<<x[n/2+1];
else cout<<x[n/2]; return 0;
}

  

codeforces 710B B. Optimal Point on a Line(数学)的更多相关文章

  1. CodeForces 710B Optimal Point on a Line (数学,求中位数)

    题意:给定n个坐标,问你所有点离哪个近距离和最短. 析:中位数啊,很明显. 代码如下: #pragma comment(linker, "/STACK:1024000000,10240000 ...

  2. [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 wi ...

  3. 【模拟】Codeforces 710B Optimal Point on a Line

    题目链接: http://codeforces.com/problemset/problem/710/B 题目大意: 给N个点的坐标,在X轴上找到最靠左的点使得这个点到N个点距离之和最小. 题目思路: ...

  4. CodeForces 710B Optimal Point on a Line

    递推. 先对$a[i]$进行从小到大排序. 然后计算出每个点左边所有点到这个点的距离之和$L[i]$,以及右边每个点到这个点的距离之和$R[i]$. 这两个都可以递推得到. $L\left[ i \r ...

  5. 「暑期训练」「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 ...

  6. codeforces 622D D. Optimal Number Permutation(找规律)

    D. Optimal Number Permutation time limit per test 1 second memory limit per test 256 megabytes input ...

  7. Codeforces Round #247 (Div. 2) B - Shower Line

    模拟即可 #include <iostream> #include <vector> #include <algorithm> using namespace st ...

  8. codeforces#253 D - Andrey and Problem里的数学知识

    这道题是这种,给主人公一堆事件的成功概率,他仅仅想恰好成功一件. 于是,问题来了,他要选择哪些事件去做,才干使他的想法实现的概率最大. 我的第一个想法是枚举,枚举的话我想到用dfs,但是认为太麻烦. ...

  9. Codeforces Round #376 (Div. 2) F. Video Cards 数学,前缀和

    F. Video Cards time limit per test 1 second memory limit per test 256 megabytes input standard input ...

随机推荐

  1. iOS js oc相互调用(JavaScriptCore)---js调用iOS --js里面通过对象调用方法

    下来我们看第二种情况 就是js 中是通过一个对象来调用方法的. 此处稍微复杂一点我们需要使用到 JSExport 凡事添加了JSExport协议的协议,所规定的方法,变量等 就会对js开放,我们可以通 ...

  2. 微信小程序的文件结构 —— 微信小程序教程系列(1)

    所有文章均是CSDN博客所看,已按照作者要求,注明出处了,感谢作者的整理! 博客文章地址:http://blog.csdn.net/michael_ouyang/article/details/548 ...

  3. window下安装php7的memcache扩展

    安装memcache:http://www.runoob.com/memcached/memcached-connection.html1.4.4 c:\memcached\memcached.exe ...

  4. 在Linux中显示日历(cal)

    cal 2013    显示2013年整年日历 cal 7 2013  显示2013年 7 月 日历

  5. JAVA中sleep() 和 wait() 有什么差别?

    (网上的答案:sleep是线程类(Thread)的方法,导致此线程暂停运行指定时间,将运行机会给其它线程.可是监控状态依旧保持,到时后会自己主动恢复.调用sleep不会释放对象锁. wait是Obje ...

  6. mysql存储过程之事务篇

    mysql存储过程之事务篇 事务的四大特征: ACID:Atomic(原子性).Consistent(一致性).Isolated(独立性).Durable (持久性) MySQL的事务支持不是绑定在M ...

  7. Linux的分区

    1.磁盘分区 主分区: 最多只能有4个 扩展分区: 最多只能有1个 主分区加扩展分区最多只能有4个 不能写入数据,只能包含逻辑逻辑分区 逻辑分区: 磁盘号从5开始,只要看到磁盘号是5,一定是逻辑分区 ...

  8. Bootstrap学习4--Table样式(转载:https://blog.csdn.net/Fanbin168/article/details/53208869)

    备注:最新Bootstrap手册:http://www.jqhtml.com/bootstraps-syntaxhigh/index.html 将<table>标签添加class=‘tab ...

  9. linux shell 字符串操作(长度,查找,替换)

    感谢原创,文章很有帮助. 转自:http://www.cnblogs.com/chengmo/archive/2010/10/02/1841355.html 一.判断读取字符串值 表达式 含义 ${v ...

  10. mysql主从复制(linux下)

    转至:http://369369.blog.51cto.com/319630/790921 怎么安装mysql数据库,这里不说了,只说它的主从复制,步骤如下: 1.主从服务器分别作以下操作:   1. ...