【模拟】Codeforces 710B Optimal Point on a Line
题目链接:
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的更多相关文章
- CodeForces 710B Optimal Point on a Line (数学,求中位数)
题意:给定n个坐标,问你所有点离哪个近距离和最短. 析:中位数啊,很明显. 代码如下: #pragma comment(linker, "/STACK:1024000000,10240000 ...
- CodeForces 710B Optimal Point on a Line
递推. 先对$a[i]$进行从小到大排序. 然后计算出每个点左边所有点到这个点的距离之和$L[i]$,以及右边每个点到这个点的距离之和$R[i]$. 这两个都可以递推得到. $L\left[ i \r ...
- codeforces 710B B. Optimal Point on a Line(数学)
题目链接: B. Optimal Point on a Line 题意: 给出n个点,问找出一个点使得这个点到所有的点的距离和最小; 思路: 所有点排序后的中位数;这是一个结论; AC代码: #inc ...
- [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 ...
- [Codeforces 1214A]Optimal Currency Exchange(贪心)
[Codeforces 1214A]Optimal Currency Exchange(贪心) 题面 题面较长,略 分析 这个A题稍微有点思维难度,比赛的时候被孙了一下 贪心的思路是,我们换面值越小的 ...
- 「暑期训练」「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 ...
- 贪心+模拟 Codeforces Round #288 (Div. 2) C. Anya and Ghosts
题目传送门 /* 贪心 + 模拟:首先,如果蜡烛的燃烧时间小于最少需要点燃的蜡烛数一定是-1(蜡烛是1秒点一支), num[g[i]]记录每个鬼访问时已点燃的蜡烛数,若不够,tmp为还需要的蜡烛数, ...
- 模拟 Codeforces Round #203 (Div. 2) C. Bombs
题目地址:http://codeforces.com/problemset/problem/350/C /* 题意:机器人上下左右走路,把其他的机器人都干掉要几步,好吧我其实没读懂题目, 看着样例猜出 ...
- 模拟 Codeforces Round #249 (Div. 2) C. Cardiogram
题目地址:http://codeforces.com/contest/435/problem/C /* 题意:给一组公式,一组数据,计算得到一系列的坐标点,画出折线图:) 模拟题:蛮恶心的,不过也简单 ...
随机推荐
- oracle重建、更新索引、索引统计信息命令
在oracle中查找所有的表的索引的命令 select t.*,i.index_type from user_ind_columns t,user_indexes i where t.index_na ...
- mxnet运行时遇到问题及解决方法
1.训练好模型之后,进行预测时出现这种错误: mxnet.::] src/ndarray/ndarray.cc:: Check failed: ,) to.shape=(,) 这种问题的解决方法,在全 ...
- maven 依赖冲突的问题
如果原始系统的jarA依赖jarB1.0 而新引入的jarC依赖jarB2.0 导致系统启动报错,提示冲突,这时为了保证原始系统的稳定性, 在pom.xml文件中引入jarC时,需要exclude掉j ...
- c# try..... catch
功能说明:在此例中,try 块包含对可能导致异常的ProcessString()方法的调用.catch子句包含仅在屏幕上显示消息的异常处理程序,当从ProcessString内部调用throw语句时, ...
- iOS 中如何监测某段代码运行的时间
在iOS里面有时间涉及到网络请求,有时间涉及到数据库的查询,我们需要计算该段代码的效率, 以及执行时间方面的问题,为此,可以使用下面方法: double a = CFAbsoluteTimeGetCu ...
- 06MySQL数据库入门
1.数据库的概念 数据库是保存数据的仓库,可以方便的把数据放进去,并且把数据根据各种需求取出来. 数据库管理系统(Database Management System,DBMS)是对数据库进行管理(增 ...
- [转]Mysql导入导出工具Mysqldump和Source命令用法详解
Mysql本身提供了命令行导出工具Mysqldump和Mysql Source导入命令进行SQL数据导入导出工作,通过Mysql命令行导出工具Mysqldump命令能够将Mysql数据导出为文本格式( ...
- Vijos1386 IOI2007 矿工配餐 动态规划
感觉早些年IOI的题都不难啊,也就NOIp难度……现在貌似变难了 状态用dp[n][a1][b1][a2][b2]表示 n表示处理到前n个餐车 第一组矿工得到的最近一种食物用a1表示,a1的上一种食物 ...
- java获取数据库数据表的元数据
Connction conn; DatabaseMetaData dmd=conn.getMetaData();//获取数据库元数据 PreparedStatment ps; ps.getParame ...
- php开发利器
phpstorm 当前版本2016.1 之前用的为Zend studio,比之notepad++确实方便很多,不过很多方面还是不方便的,比如定位文件,上传下载到svn什么的. 看到phpstorm新版 ...