3170: [Tjoi 2013]松鼠聚会
来源:互联网 发布:设计师导航网源码 编辑:程序博客网 时间:2024/03/29 14:35
3170: [Tjoi 2013]松鼠聚会
Time Limit: 10 Sec Memory Limit: 128 MBSubmit: 1077 Solved: 536
[Submit][Status][Discuss]
Description
有N个小松鼠,它们的家用一个点x,y表示,两个点的距离定义为:点(x,y)和它周围的8个点即上下左右四个点和对角的四个点,距离为1。现在N个松鼠要走到一个松鼠家去,求走过的最短距离。
Input
第一行给出数字N,表示有多少只小松鼠。0<=N<=10^5
下面N行,每行给出x,y表示其家的坐标。
-10^9<=x,y<=10^9
Output
表示为了聚会走的路程和最小为多少。
Sample Input
6
-4 -1
-1 -2
2 -4
0 2
0 3
5 -2
-4 -1
-1 -2
2 -4
0 2
0 3
5 -2
Sample Output
20
HINT
Source
#include<iostream>#include<cstdio>#include<queue>#include<vector>#include<bitset>#include<algorithm>#include<cstring>#include<map>#include<stack>#include<set>#include<cmath>#include<ext/pb_ds/priority_queue.hpp>using namespace std;const int maxn = 1E5 + 10;typedef long long LL;const LL two = 2;struct Point{LL x,y,pos;Point(){}Point(LL x,LL y,int pos): x(x),y(y),pos(pos){}}point[maxn];int n;LL ans[maxn],sum[maxn];bool cmp1(const Point &a,const Point &b) {return a.x < b.x;}bool cmp2(const Point &a,const Point &b) {return a.y < b.y;}int main(){#ifdef DMCfreopen("DMC.txt","r",stdin);#endifcin >> n;if (!n) {cout << 0; return 0;}for (int i = 1; i <= n; i++) {int x,y; scanf("%d%d",&x,&y);point[i] = Point(1LL*(x-y),1LL*(x+y),i);}sort(point + 1,point + n + 1,cmp1);for (int i = 1; i <= n; i++) sum[i] = sum[i-1] + point[i].x;for (int i = 1; i <= n; i++) {LL now = 0;now += (1LL*(i-1)*point[i].x - sum[i-1]);now += (sum[n] - sum[i] - 1LL*(n-i)*point[i].x);ans[point[i].pos] += now;}sort(point + 1,point + n + 1,cmp2);for (int i = 1; i <= n; i++) sum[i] = sum[i-1] + point[i].y;for (int i = 1; i <= n; i++) {LL now = 0;now += (1LL*(i-1)*point[i].y - sum[i-1]);now += (sum[n] - sum[i] - 1LL*(n-i)*point[i].y);ans[point[i].pos] += now;}LL Ans = 1E18;for (int i = 1; i <= n; i++) Ans = min(Ans,ans[i]);cout << Ans/two;return 0;}
0 0
- 3170: [Tjoi 2013]松鼠聚会
- 3170: [Tjoi 2013]松鼠聚会
- 3170: [Tjoi 2013]松鼠聚会 (中位数)
- BZOJ 3170: [Tjoi 2013]松鼠聚会
- BZOJ 3170 [Tjoi 2013]松鼠聚会
- bzoj 3170: [Tjoi 2013]松鼠聚会
- bzoj 3170: [Tjoi 2013]松鼠聚会
- [BZOJ3170] [Tjoi 2013]松鼠聚会
- BZOJ3170: [Tjoi 2013]松鼠聚会
- 杂题 [Tjoi 2013]松鼠聚会
- 【bzoj3170】[Tjoi 2013]松鼠聚会
- BZOJ 3170([Tjoi 2013]松鼠聚会-Manhattan距离单点最近)
- BZOJ 3170([Tjoi 2013]松鼠聚会-Manhattan距离单点最近)
- BZOJ 3170 Tjoi 2013 松鼠聚会 计算几何
- bzoj 3170: [Tjoi 2013]松鼠聚会 计算几何
- BZOJ P3170: [Tjoi 2013]松鼠聚会
- BZOJ 3170 TJOI 2013 松鼠聚会 切比雪夫距离
- BZOJ 3170: [Tjoi 2013]松鼠聚会(切比雪夫距离)
- Universal-Image-Loader
- Java中的CompareAndSet(CAS)
- Shell排序
- POJ 2253 Frogger(青蛙跳石头)
- Zend Studio使用教程之自定义并注册Zend Studio(1/2)
- 3170: [Tjoi 2013]松鼠聚会
- 秒杀多线程第十篇 读者写者问题
- 新浪微博之链式运动
- [code generation]模版引擎比较_freemarker 和 velocity
- openwrt: Makefile 框架分析
- HDU 1124 (求阶乘中0的个数)
- 外观模式
- 看了极光推送技术原理的几点思考
- StringBuilder、StringBuffer和String三者的联系和区别