输油管道

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. 使用Web Workers处理线程

    使用HTML 4和JavaScript创建出来的Web程序中,因为所有的处理都是在单线程中 HTML 5的Web Workers API,HTML 5中,一个Worker实际上为一个后台运行的线程.

  2. PCB 内网实现《OCR文字识别》实现逻辑

    一.实现内网信息获取网络图 二. OCR文字识别,运用技术点(啰嗦了,即然写了就都写了一遍) 三. C#客户端实现界面, 设置界面描述功能待完善,

  3. PCB拼板之单一矩形排样算法

    算法实现相关内容整理如下: 一.排样变量与关系 此算法,基于固定4边的尺寸遍历每个单只板的长宽得到最优解. 二.条件约束 基本约束条件(参考上图变量) 三.排样图形相同类型规律 由于计算量大,为了有效 ...

  4. php的string编码类型

    在php中字符编码转换我们一般会用到iconv与mb_convert_encoding进行操作,但是mb_convert_encoding在转换性能上比iconv要差很多哦.string iconv ...

  5. Python 32 通信循环 连接循环 粘包问题

    一:通信循环 二:连接循环 三:粘包问题

  6. VS2015 右侧导航插件地址

    右侧导航插件: https://marketplace.visualstudio.com/items?itemName=VisualStudioProductTeam.ProductivityPowe ...

  7. OneThink管理平台 ,登录后台一直提示验证码错误

    可能是数据库的错.上传到服务器以后要改2个地方的配置,\Application\Common\Conf\config.php(整站公用配置文 件),\Application\User\Conf\con ...

  8. Java中的synchronized

    学习 https://blog.csdn.net/a158123/article/details/78607964 以及 https://www.cnblogs.com/beiyetengqing/p ...

  9. CSS命名规则和如何命名

    CSS命名规则 头:header 内容:content/containe 尾:footer 导航:nav 侧栏:sidebar 栏目:column 页面外围控制整体布局宽度:wrapper 左右中:l ...

  10. angular js shopping

    <!DOCTYPE html>   <html lang="en">   <head>   <meta charset="UTF ...