博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
hdu 4312 Meeting point-2(4级)
阅读量:5297 次
发布时间:2019-06-14

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

Meeting point-2

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 866    Accepted Submission(s): 472
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.
It's an opportunity to show yourself in front of your predecessors!
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, all 8 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), (x-1,y+1), (x-1,y-1), (x+1,y+1), (x+1,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
 
20 15 14 38
Hint
In the first case, the meeting point is (0,2); the second is (0,0), the third is (1,-1) and the last is (-1,-1)
 
Author
TJU
 
Source
 
Recommend
zhuyuanchen520

思路:

max{|x|,|y|}=1/2(|x+y|+|x-y|);

因此将x变成x+y,y->x-y;就可以算曼哈顿距离了。

x,y到某点的曼哈顿距离可以分开算,因此,分开枚举以某点为中心的值球最小就好了。

           预处理,kx[x]以某点 x为中心的所有x距离和,ky[]同理。kx[i]=kx[i-1]+(i-n+i)*(f[i].x-f[i-1].x);

另外还有一种很狗屎的办法,猜测+枚举,运气好的话,数据不是非常强就可以过。

就是将其按照 X,Y排序,答案在中间段取点,但应该枚举几个呢???这是个问题,所以有点狗屎

#include
#include
#include
#include
using namespace std;const int mm=2e5+9;class node{public: __int64 x,y; int id;} f[mm];bool cmpx(node a,node b){ return a.x
ky[i]+kx[f[i].id])sum=ky[i]+kx[f[i].id]; } printf("%I64d\n",sum/2); } } return 0;}
///250以下基本就错了,以上基本就超了。

#include 
#include
#include
#include
#include
using namespace std;const int maxn = 1000010;pair
p[maxn];int abs1(int a) { return a<0?-a:a;}int main(){ int T,n; scanf("%d",&T); while(T--) { scanf("%d",&n); for(int i=0;i

转载于:https://www.cnblogs.com/nealgavin/archive/2013/06/01/3206085.html

你可能感兴趣的文章
boost库使用:vs2013下boost::container::vector编译出错解决
查看>>
通过httplib2 探索的学习的最佳方式
查看>>
理解运算符重载 4
查看>>
快来熟练使用 Mac 编程
查看>>
第二周
查看>>
Node.js 入门:Express + Mongoose 基础使用
查看>>
plsql使用,为什么可以能看见其他用户的表
查看>>
一步步教你轻松学奇异值分解SVD降维算法
查看>>
使用pager进行分页
查看>>
UVA - 1592 Database
查看>>
Min Stack
查看>>
从LazyPhp说起
查看>>
Fine Uploader文件上传组件
查看>>
javascript中的传递参数
查看>>
objective-c overview(二)
查看>>
python查询mangodb
查看>>
软件测试(基础理论一)摘
查看>>
consonant combination
查看>>
基于Flutter实现的仿开眼视频App
查看>>
析构器
查看>>