输油管道

Time Limit: 2000/1000MS (Java/Others) Memory Limit: 262144/131072KB (Java/Others)
 

Problem Description

平面上有n个油井,现在要建立一条主干线,用来把所有的油井产出的原油都输送出去,主干线是平行于x轴的一条直线,每个油井通过一条支线把原油输送到主干线上,现在给定n个油井在平面上的坐标,那么应该把主干线建在什么地方才能让所有的支干线的总长度最小呢?

Input

首先一个正整数n,接下来n行每行两个整数,代表n个油井在平面上的位置。n和坐标都是小于等于1000000的正整数。

Output

输出总的支干线长度的最小值,每个结果占一行。

Sample Input

2
0 0
10 10

Sample Output

10

Source

第九届北京化工大学程序设计竞赛

Manager

 
解题:中位数的运用
 #include <bits/stdc++.h>
using namespace std;
const int maxn = ;
typedef long long LL;
LL y[maxn],x;
int main(){
int n;
while(~scanf("%d",&n)){
for(int i = ; i < n; ++i)
scanf("%lld%lld",&x,y+i);
sort(y,y+n);
LL mid = y[(n-)>>],ret = ;
for(int i = ; i < n; ++i)
ret += abs(y[i] - mid);
printf("%lld\n",ret);
}
return ;
}

ACdream 1735 输油管道的更多相关文章

  1. acdream 1735 输油管道 贪心

    输油管道 Time Limit: 20 Sec  Memory Limit: 256 MB 题目连接 http://acdream.info/problem?pid=1735 Description ...

  2. ACdream 1735 输油管道 (排序)

    http://acdream.info/problem?pid=1735 官方题解:http://acdream.info/topic?tid=4246 因为主干线是平行于x轴的直线,那么跟x坐标其实 ...

  3. ACdream - 1735:输油管道

    Time Limit: 2000/1000MS (Java/Others) Memory Limit: 262144/131072KB (Java/Others) Problem Descriptio ...

  4. acoj-1735 输油管道 【中位数】

    题目链接:http://acdream.info/problem?pid=1735 输油管道 Time Limit: 2000/1000MS (Java/Others) Memory Limit: 2 ...

  5. ACdream 1214---矩阵连乘

    ACdream 1214---矩阵连乘 Problem Description You might have noticed that there is the new fashion among r ...

  6. acdream.LCM Challenge(数学推导)

     LCM Challenge Time Limit:1000MS     Memory Limit:64000KB     64bit IO Format:%lld & %llu Submit ...

  7. acdream.Triangles(数学推导)

    Triangles Time Limit:1000MS     Memory Limit:64000KB     64bit IO Format:%lld & %llu Submit Stat ...

  8. acdream.A Very Easy Triangle Counting Game(数学推导)

    A - A Very Easy Triangle Counting Game Time Limit:1000MS     Memory Limit:64000KB     64bit IO Forma ...

  9. acdream.Bet(数学推导)

    Bet Time Limit:1000MS     Memory Limit:64000KB     64bit IO Format:%lld & %llu Submit Status Pra ...

随机推荐

  1. @SpringBootApplication注解

    @SpringBootApplication注解表明了SpringBoot的核心功能,即自动配置. @SpringBootApplication(主配置类): @SpringBootConfigura ...

  2. Mongodb---记一次事故故障

    2014.06.19.001---故障报告 事故发生时间 事故简述 事故责任方 是否解决 19:21-20:15 IISserverD盘即将溢出 是 一.事故描写叙述: 在19:21收到警报.显示II ...

  3. Extjs grid 某列点击弹窗

    { header : "单号", tooltip : '单号', dataIndex : 'transportCode', width : 130, sortable : true ...

  4. luogu1984 [SDOI2008] 烧水问题

    题目描述 给出水的比热容.冰点和沸点,问将$n$杯有$\frac{1}{n}\mathrm{kg}$的水从冰点加热到沸点所需最小热量.不一定相邻的两杯水间可以无热量损失地热传递至两者温度相同. 题解 ...

  5. oracle buffer cache的基本原理

    Buffer cache 的原理 一. 1·)当一个服务器进程需要读数据到buffer cache中时,首先必须判断该数据在buffer 中是否存在,如果存在且可用,则获取该数据,根据lru算法在lr ...

  6. heap堆&&priority_queue优先队列

    堆(heap)不是stl中的东西...它分为 max heap 和min heap. 但我不想用这些,而是采用了priority_queue,优先队列,定义在queue中.顾名思义,它的作用就是无论怎 ...

  7. RPC通信框架——RCF介绍

    现有的软件中用了大量的COM接口,导致无法跨平台,当然由于与Windows结合的太紧密,还有很多无法跨平台的地方.那么为了实现跨平台,支持Linux系统,以及后续的分布式,首要任务是去除COM接口. ...

  8. LA3276

    费用流 这种棋盘模型大概都是网络流吧 首先我们知道棋子之间不会影响到达目标的步数,那么就好做了,枚举终点,然后就是最小权匹配了,因为就是寻找总和最小,然后费用流就行了. #include<bit ...

  9. SPOJ GSS1 & GSS3&挂了的GSS5

    线段树然后yy一下,搞一搞. GSS1: 题意:求最大区间和. #include <cstdio> #include <algorithm> using namespace s ...

  10. Android常见错误整理

    1.当我new class的时候,提示以下错误: Unable to parse template "Class" Error message: This template did ...