CodeForces 710B Optimal Point on a Line (数学,求中位数)
题意:给定n个坐标,问你所有点离哪个近距离和最短。
析:中位数啊,很明显。
代码如下:
#pragma comment(linker, "/STACK:1024000000,1024000000")
#include <cstdio>
#include <string>
#include <cstdlib>
#include <cmath>
#include <iostream>
#include <cstring>
#include <set>
#include <queue>
#include <algorithm>
#include <vector>
#include <map>
#include <cctype>
#include <stack>
#define freopenr freopen("in.txt", "r", stdin)
#define freopenw freopen("out.txt", "w", stdout)
using namespace std; typedef long long LL;
typedef pair<int, int> P;
const int INF = 0x3f3f3f3f;
const double inf = 0x3f3f3f3f3f3f;
const LL LNF = 100000000000000000;
const double PI = acos(-1.0);
const double eps = 1e-8;
const int maxn = 3e5 + 5;
const int mod = 1e9 + 7;
const char *mark = "+-*";
const int dr[] = {-1, 0, 1, 0};
const int dc[] = {0, 1, 0, -1};
int n, m;
inline bool is_in(int r, int c){
return r >= 0 && r < n && c >= 0 && c < m;
}
inline LL Max(LL a, LL b){ return a < b ? b : a; }
inline LL Min(LL a, LL b){ return a > b ? b : a; }
inline int Max(int a, int b){ return a < b ? b : a; }
inline int Min(int a, int b){ return a > b ? b : a; }
char s[10];
int a[maxn]; int main(){
while(scanf("%d", &n) == 1){
for(int i = 1; i <= n; ++i) scanf("%d", &a[i]);
int t = (n+1)/2;
sort(a+1, a+n+1);
printf("%d\n", a[t]);
}
return 0;
}
CodeForces 710B Optimal Point on a Line (数学,求中位数)的更多相关文章
- 【模拟】Codeforces 710B Optimal Point on a Line
题目链接: http://codeforces.com/problemset/problem/710/B 题目大意: 给N个点的坐标,在X轴上找到最靠左的点使得这个点到N个点距离之和最小. 题目思路: ...
- 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 Educational Codeforces Round 5 E. Sum of Remainders 数学
E. Sum of Remainders 题目连接: http://www.codeforces.com/contest/616/problem/E Description The only line ...
- Codeforces 810C Do you want a date?(数学,前缀和)
C. Do you want a date? time limit per test:2 seconds memory limit per test:256 megabytes input:stand ...
- Codeforces Round #499 (Div. 2) C. Fly(数学+思维模拟)
C. Fly time limit per test 1 second memory limit per test 256 megabytes input standard input output ...
随机推荐
- Kafka中的Message Delivary机制
学习Kafka的读书笔记,暂未把文章设为翻译类型,因为并非直译文档.水平有限,还请路过高手指正. <1> “最多(发送)一次”(At most once):消息可以丢失但绝不会重新发送:& ...
- PHP全栈工程师学习大纲
一.高性能网站开发功力提升 时间 标题 内容概要 2015-12-28 开学典礼以及工程师成长路线图 工程师成长的发展路径图.三个阶段,在各个阶段需要提升自己的地方,从技术上也讲了一些提高分析代码的工 ...
- (转)gLFlush()和gLFinish()
笔者初使用OpenGL之时,所遇到的命令不能生效的问题:比如开始想用gLClearColor来设置背景色为红色,结果执行后背景还是默认的黑色.后来查阅资料,才知道这与OpenGL的指令执行流程有关,要 ...
- python工厂方式创建list
>>> l = list('sdfsdf') >>> l ['s', 'd', 'f', 's', 'd', 'f']
- 安装Oracle 11g RAC R2 之Linux DNS 配置
Oracle 11g RAC 集群中引入了SCAN(Single Client Access Name)的概念,也就是指集群的单客户端访问名称.SCAN 这个特性为客户端提供了单一的主机名,用于访问集 ...
- OpenGL学习之路(三)
1 引子 这些天公司一次次的软件发布节点忙的博主不可开交,另外还有其它的一些事也占用了很多时间.现在坐在电脑前,在很安静的环境下,与大家分享自己的OpenGL学习笔记和理解心得,感到格外舒服.这让我回 ...
- Java 中的二维数组
所谓二维数组,可以简单的理解为是一种“特殊”的一维数组,它的每个数组空间中保存的是一个一维数组. 那么如何使用二维数组呢,步骤如下: 1. 声明数组并分配空间 或者 如: 2. 赋值 二维数组的赋值, ...
- Markdown解决需要输入两个回车才能为一个空行的问题
markdownDataDiv.children().each(function(){ $(this).html($(this).html().replaceAll("\n",&q ...
- 如何在MySql中记录SQL日志
SQL server有一个sql profiler可以实时跟踪服务器执行的SQL语句,这在很多时候调试错误非常有用.例如:别人写的复杂代码.生产系统.无调试环境.无原代码... ... 查了一下资 ...
- ios 内存管理 心得
- alloc, copy, retain会把引用计数+1 - release会把引用计数-1 - 局部变量如果初始化时不是autorelease的,要及时调用release释放,并且赋值为nil否则 ...