博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Hdu 4311-Meeting point-1 曼哈顿距离,前缀和
阅读量:7094 次
发布时间:2019-06-28

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

题目:

Meeting point-1

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)

Total Submission(s): 3426    Accepted Submission(s): 1131

Problem Description
It has been ten years since TJU-ACM established. And in this year all the retired TJU-ACMers want to get together to celebrate the tenth anniversary. Because the retired TJU-ACMers may live in different places around the world, it may be hard to find out where to celebrate this meeting in order to minimize the sum travel time of all the retired TJU-ACMers. 
There is an infinite integer grid at which N retired TJU-ACMers have their houses on. They decide to unite at a common meeting place, which is someone's house. From any given cell, only 4 adjacent cells are reachable in 1 unit of time.
Eg: (x,y) can be reached from (x-1,y), (x+1,y), (x, y-1), (x, y+1).
Finding a common meeting place which minimizes the sum of the travel time of all the retired TJU-ACMers.
 

 

Input
The first line is an integer T represents there are T test cases. (0<T <=10)
For each test case, the first line is an integer n represents there are n retired TJU-ACMers. (0<n<=100000), the following n lines each contains two integers x, y coordinate of the i-th TJU-ACMer. (-10^9 <= x,y <= 10^9)
 

 

Output
For each test case, output the minimal sum of travel times.
 

 

Sample Input
4 6 -4 -1 -1 -2 2 -4 0 2 0 3 5 -2 6 0 0 2 0 -5 -2 2 -2 -1 2 4 0 5 -5 1 -1 3 3 1 3 -1 1 -1 10 -1 -1 -3 2 -4 4 5 2 5 -4 3 -1 4 3 -1 -2 3 4 -2 2
 

 

Sample Output
26 20 20 56
Hint
In the first case, the meeting point is (-1,-2); the second is (0,0), the third is (3,1) and the last is (-2,2)
 

 

Author
TJU
 

 

Source
 

 

Recommend
zhuyuanchen520   |   We have carefully selected several similar problems for you:            
 
题意:给你n个点的坐标,让你找其中一个坐标,使得所有点到那个点的曼哈顿距离和最小。
题解:
曼哈顿距离+前缀和
把x和y分别排序,然后去维护分别排序后的前缀和,还有前缀和的前缀和。
注意开long long
1 #include
2 using namespace std; 3 #define MAXN 100010 4 #define INF 10000000000000000LL 5 #define LL long long 6 LL qx[MAXN],qy[MAXN],qx1[MAXN],qy1[MAXN]; 7 LL ans[MAXN]; 8 struct node 9 {10 int a,id;11 }x[MAXN],y[MAXN];12 int read()13 {14 int s=0,fh=1;char ch=getchar();15 while(ch<'0'||ch>'9'){
if(ch=='-')fh=-1;ch=getchar();}16 while(ch>='0'&&ch<='9'){s=s*10+(ch-'0');ch=getchar();}17 return s*fh;18 }19 bool cmp(node aa,node bb)20 {21 return aa.a

 

转载于:https://www.cnblogs.com/Var123/p/5355984.html

你可能感兴趣的文章
NEC向日本三好市提供基于面部识别的盖章及旅游APP服务
查看>>
#22 进程、优先级管理命令:vmstat、pmap、htop、glances、dstat、kill、killall、pkill、bg、fg、nice......
查看>>
光伏补贴降温
查看>>
新“幽灵主机”技术加强僵尸网络生存能力
查看>>
光伏“第三矩阵”企业为何不理想?
查看>>
英特尔公司CEO科再奇:数据是未来无人驾驶的新“石油”
查看>>
Qualcomm与TDK宣布联手成立合资公司
查看>>
Mirai新攻击 导致非洲一国全断网
查看>>
一个需求价值评估的方法——靶图
查看>>
Loadrunner11无法启动IE的解决办法
查看>>
强大的PyTorch:10分钟让你了解深度学习领域新流行的框架
查看>>
钉钉争议的冷思考:犀利表象下暗藏平等理念
查看>>
美国互联网公司欲修复与特朗普关系 呼吁支持加密
查看>>
mybatis中动态sql常用的标签
查看>>
“大数据风控”方兴未艾,最终需要的还是硬技术
查看>>
互联汽车面临的网络安全问题
查看>>
菜鸟也能飞:SQL数据库实战专业教程(三)
查看>>
Android启动过程深入解析
查看>>
五个维度相互关联全面分析智能硬件与物联网行业
查看>>
帮助首席执行官了解大数据项目的三大技巧
查看>>