题目链接:

  http://codeforces.com/problemset/problem/710/B

题目大意:

  给N个点的坐标,在X轴上找到最靠左的点使得这个点到N个点距离之和最小。

题目思路:

  【模拟】

  先将N个点坐标排序,找夹在i中间的坐标即为答案。(中间2个数选左边的)

  从点坐标是X的点往左移到X+1,代价是X右边的坐标数-左边的坐标数。当X不是给定的坐标时答案是不会变得。

  所以最终寻找的这个点一定是N个点中个某个点。并且就在正中中间的位置。如果正中间有两个数,那么这两个数之间的任何值都是最优的,输出最左的。

 //
//by coolxxx
//#include<bits/stdc++.h>
#include<iostream>
#include<algorithm>
#include<string>
#include<iomanip>
#include<map>
#include<memory.h>
#include<time.h>
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
//#include<stdbool.h>
#include<math.h>
#define min(a,b) ((a)<(b)?(a):(b))
#define max(a,b) ((a)>(b)?(a):(b))
#define abs(a) ((a)>0?(a):(-(a)))
#define lowbit(a) (a&(-a))
#define sqr(a) ((a)*(a))
#define swap(a,b) ((a)^=(b),(b)^=(a),(a)^=(b))
#define mem(a,b) memset(a,b,sizeof(a))
#define eps (1e-8)
#define J 10
#define mod 1000000007
#define MAX 0x7f7f7f7f
#define PI 3.14159265358979323
#define N 300004
using namespace std;
typedef long long LL;
int cas,cass;
int n,m,lll,ans;
int a[N];
int main()
{
#ifndef ONLINE_JUDGE
// freopen("1.txt","r",stdin);
// freopen("2.txt","w",stdout);
#endif
int i,j,k;
// for(scanf("%d",&cas);cas;cas--)
// for(scanf("%d",&cas),cass=1;cass<=cas;cass++)
// while(~scanf("%s",s+1))
while(~scanf("%d",&n))
{
for(i=;i<=n;i++)
{
scanf("%d",&a[i]);
}
sort(a+,a++n);
printf("%d\n",a[(n+)/]);
}
return ;
}
/*
// //
*/

【模拟】Codeforces 710B Optimal Point on a Line的更多相关文章

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

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

  2. CodeForces 710B Optimal Point on a Line

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

  3. codeforces 710B B. Optimal Point on a Line(数学)

    题目链接: B. Optimal Point on a Line 题意: 给出n个点,问找出一个点使得这个点到所有的点的距离和最小; 思路: 所有点排序后的中位数;这是一个结论; AC代码: #inc ...

  4. [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 ...

  5. [Codeforces 1214A]Optimal Currency Exchange(贪心)

    [Codeforces 1214A]Optimal Currency Exchange(贪心) 题面 题面较长,略 分析 这个A题稍微有点思维难度,比赛的时候被孙了一下 贪心的思路是,我们换面值越小的 ...

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

  7. 贪心+模拟 Codeforces Round #288 (Div. 2) C. Anya and Ghosts

    题目传送门 /* 贪心 + 模拟:首先,如果蜡烛的燃烧时间小于最少需要点燃的蜡烛数一定是-1(蜡烛是1秒点一支), num[g[i]]记录每个鬼访问时已点燃的蜡烛数,若不够,tmp为还需要的蜡烛数, ...

  8. 模拟 Codeforces Round #203 (Div. 2) C. Bombs

    题目地址:http://codeforces.com/problemset/problem/350/C /* 题意:机器人上下左右走路,把其他的机器人都干掉要几步,好吧我其实没读懂题目, 看着样例猜出 ...

  9. 模拟 Codeforces Round #249 (Div. 2) C. Cardiogram

    题目地址:http://codeforces.com/contest/435/problem/C /* 题意:给一组公式,一组数据,计算得到一系列的坐标点,画出折线图:) 模拟题:蛮恶心的,不过也简单 ...

随机推荐

  1. hdu 5073 Galaxy

    题意是给定n个点,让求找到一个点p使得sigma( (a[i] - p) ^ 2 ) 最小,其中a[i]表示第i个点的位置.其中有k个点不用算. 思路:发现这道题其实就是求n-k个点方差. 那么推一下 ...

  2. 导出到excel

    /// <summary> /// 导出 /// </summary> /// <param name="table">数据表</para ...

  3. android SDK 代理配置(东北大学)

    启动 Android SDK Manager ,打开主界面,依次选择「Tools」.「Options...」,弹出『Android SDK Manager - Settings』窗口: 在『Andro ...

  4. SQLSERVER 触发器 将一个服务器上的数据库中数据插入到另一个服务器上的数据库中怎么做

    首先要执行 sp_addlinkedserver '服务器ip' 然后开始写语句 insert into ip.库名字.dbo.table select * from iserted

  5. OpenSSL安装及目录介绍

    1. 下载安装OpenSSL 2. 根据需要下载安装Visual C++ Redistributable 3. 安装完成OpenSSL后,目录结构如下所示 其中,bin文件夹下是OpenSSL主程序的 ...

  6. 解决NSAttributedString与UILabel高度自适应计算问题

    两个类扩展方法: /** *  修改富文本的颜色 * *  @param str   要改变的string *  @param color 设置颜色 *  @param range 设置颜色的文字范围 ...

  7. TextField的文字距左边框的距离偏移

    默认情况下,当向textField输入文字时,文字会紧贴在textField左边框上. 我们可以通过设置textField的leftView,设置一个只有宽度的leftView. 这样还不够,因为默认 ...

  8. DataSet与DataTable基本用法

    http://files.cnblogs.com/files/monkeyZhong/DataSetExample.rar 在设计数据库操作或者XML操作等表格数据时,我们难免要跟DataSet和Da ...

  9. PHP中定义常量的几种方式与区别

    [问]在php中定义常量时,const与define的区别? [答]使用const使得代码简单易读,const本身就是一个语言结构,而define是一个函数.另外const在编译时要比define快很 ...

  10. hdu 3308

    终于A了,我好想砍人,虽然这是一道基础的区间合并.但是这错误我也是醉了. 错误我表在注释里. 题目意思不多说,sha崽题目出的很简洁. #include <iostream>#includ ...