输油管道

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. Kafka编程实例

    编程 Producer是一个应用程序.它创建消息并发送它们到Kafka broker中.这些producer在本质上是不同.比方.前端应用程序.后端服务.代理服务.适配器对于潜在的系统,Hadoop对 ...

  2. T4语法

    阅读目录   阅读目录 1.什么是T4? 2.vs插件的安装 3.T4初体验 4.T4语法 其实对于“T4模板”的学习,讲得最详细的还是MSDN,下面给出对应的链接,可以点开深入的了解. 回到顶部 1 ...

  3. HDU 5532 / 2015ACM/ICPC亚洲区长春站 F.Almost Sorted Array

    Almost Sorted Array Problem Description We are all familiar with sorting algorithms: quick sort, mer ...

  4. suse的安装命令zypper,类似apt

    例子:添加11.3的官方软件和升级源zypper ar http://download.opensuse.org/distribution/11.3/repo/oss/ mainzypper ar h ...

  5. B1230 [Usaco2008 Nov]lites 开关灯 线段树

    就是线段树维护异或和.之前我线段树区间修改down都是修改当前区间,结果debug出不来,改成每次向下了. 题干: Description Farmer John尝试通过和奶牛们玩益智玩具来保持他的奶 ...

  6. easyui+struts2:datagrid无法不能得到数据

    转自:https://bbs.csdn.net/topics/390980437 easyui+struts2:datagrid无法访问到指定action: userlist.jsp部分代码: XML ...

  7. nodejs express开发

    用NodeJS+Express开发WEB应用---第一篇 大漠穷秋2014-03-28 预热 为了对后面的内容理解更加透彻,推荐首先阅读下面这篇很好的文章: http://www.nodebeginn ...

  8. tpshop编辑框中上传图片过大变模糊

    tpshop编辑框中上传图片过大变模糊 图片超过2500的高就会变模糊 设置最大的高度修改一下

  9. Oracle_备份整库

    @echo off color 0b & cls echo echo 设置备份文件存放文件夹... echo set "tbuf=C:\OracleBackup" if n ...

  10. ACM_买粽子(UVA唯一的雪花)

    买粽子 Time Limit: 2000/1000ms (Java/Others) Problem Description: 端午节快到了,小蛋准备到集市上买粽子.于是周六这天,小蛋和舍友搭着公交到了 ...