博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
SHUOJ 241 Franklin's Trouble(简单数学题)
阅读量:6813 次
发布时间:2019-06-26

本文共 1566 字,大约阅读时间需要 5 分钟。

 

 

 

Franklin's Trouble

Description

Professor Franklin is consulting for an oil company, which is planning a large pipeline running east to west through an oil field of M wells. From each well, a sub-pipeline is to be connected directly to the main pipeline along a shortest path (either north or south). Given x- and y-coordinates of the wells, the professor wants to pick the optimal location of the main pipeline, which means to minimize the total length of the sub-pipelines. Franklin is not good at calculation, but you are. Can you help him?

Input

The first line of input contains a single integer N representing the number of oil fields. Then N field descriptions follow. Each field description starts with an integer M representing the number of wells in this field. Each well is represented by a point (x, y) (both x and y are integers). You can assume all integers are between 1 and 100 and no two wells share the same x-coordinate.

Output

For each field, output the total length of the sub-pipelines. The length should be minimized.

Sample Input

1

2

1 0

2 1

 

Sample Output

1

 

Explanation

In sample input, there is only one case. In this case, the main pipeline can be located at any position between y=0 and y=1 lines to reach the optimal result 1.

 

 

 

题目意思就是M个点,求一条水平线,使得所有点到水平线的距离之和最小。输出最小距离之和

输入数据的X坐标不相等。

 

很简单的数学题,明显应该选在Y坐标的中位数处,可以使得距离之和最小;;

 

#include
#include
using namespace std;const int MAXN=1000;int y[MAXN];int main(){ int T; int n; int x; scanf("%d",&T); while(T--) { scanf("%d",&n); for(int i=0;i

 

转载地址:http://xczzl.baihongyu.com/

你可能感兴趣的文章
我的友情链接
查看>>
Exchange 2010系列部署报告-域控制器部署
查看>>
Windows Server TP3之NanoServer
查看>>
squid做代理服务器实例配置
查看>>
自用PHP编码规范
查看>>
分解质因数
查看>>
[转载]阿里云服务器ubuntu安装java运行环境
查看>>
java5:运算
查看>>
防火墙配置IPsec ***
查看>>
codepro-Similar code compare
查看>>
Linux一些命令
查看>>
syn 同步!
查看>>
安装php扩展sphinx
查看>>
党援之众,无竞大义。群迷之中,无辩正论。
查看>>
svn http服务配置(1)
查看>>
Linux expect 用法
查看>>
shell脚本启动关闭tomcat,查看日志和备份项目
查看>>
玩转树莓派-RaspBerry,使用Python开发定制界面
查看>>
qt输出支持的数据库驱动
查看>>
OpenCV3中的机器学习算法
查看>>