B. Guess That Car!

题目连接:

http://codeforces.com/contest/201/problem/B

Description

A widely known among some people Belarusian sport programmer Yura possesses lots of information about cars. That is why he has been invited to participate in a game show called "Guess That Car!".

The game show takes place on a giant parking lot, which is 4n meters long from north to south and 4m meters wide from west to east. The lot has n + 1 dividing lines drawn from west to east and m + 1 dividing lines drawn from north to south, which divide the parking lot into n·m 4 by 4 meter squares. There is a car parked strictly inside each square. The dividing lines are numbered from 0 to n from north to south and from 0 to m from west to east. Each square has coordinates (i, j) so that the square in the north-west corner has coordinates (1, 1) and the square in the south-east corner has coordinates (n, m). See the picture in the notes for clarifications.

Before the game show the organizers offer Yura to occupy any of the (n + 1)·(m + 1) intersection points of the dividing lines. After that he can start guessing the cars. After Yura chooses a point, he will be prohibited to move along the parking lot before the end of the game show. As Yura is a car expert, he will always guess all cars he is offered, it's just a matter of time. Yura knows that to guess each car he needs to spend time equal to the square of the euclidean distance between his point and the center of the square with this car, multiplied by some coefficient characterizing the machine's "rarity" (the rarer the car is, the harder it is to guess it). More formally, guessing a car with "rarity" c placed in a square whose center is at distance d from Yura takes c·d2 seconds. The time Yura spends on turning his head can be neglected.

It just so happened that Yura knows the "rarity" of each car on the parking lot in advance. Help him choose his point so that the total time of guessing all cars is the smallest possible.

Input

The first line contains two integers n and m (1 ≤ n, m ≤ 1000) — the sizes of the parking lot. Each of the next n lines contains m integers: the j-th number in the i-th line describes the "rarity" cij (0 ≤ cij ≤ 100000) of the car that is located in the square with coordinates (i, j).

Output

In the first line print the minimum total time Yura needs to guess all offered cars. In the second line print two numbers li and lj (0 ≤ li ≤ n, 0 ≤ lj ≤ m) — the numbers of dividing lines that form a junction that Yura should choose to stand on at the beginning of the game show. If there are multiple optimal starting points, print the point with smaller li. If there are still multiple such points, print the point with smaller lj.

Please do not use the %lld specifier to read or write 64-bit integers in С++. It is preferred to use the cin, cout streams or the %I64d specifier.

Sample Input

2 3

3 4 5

3 9 1

Sample Output

392

1 1

Hint

题意

有一个n*m的矩阵,每个矩阵的格子边长都是4,然后每个格子中央都有一个权值为a[i][j]的车

然后你需要选择一个点,这个点必须是格子的交点

这个点的权值是sigma(dis*dis*a[i][j]),dis是这个点到a[i][j]这辆车的距离

然后让你求出一个距离最小的点

题解:

dis显然可以分开,分成x轴和y轴

然后我们就可以把这个问题转化为1维的问题解决了

相当于类似扫描线一样,扫一遍就好了

代码

#include<bits/stdc++.h>
using namespace std;
const int maxn = 1050;
long long a[maxn][maxn];
long long c[maxn],l[maxn];
long long ansx[maxn],ansy[maxn];
int main()
{
int n,m;
scanf("%d%d",&n,&m);
for(int i=0;i<n;i++)
{
for(int j=0;j<m;j++)
{
scanf("%lld",&a[i][j]);
c[i]+=a[i][j];
l[j]+=a[i][j];
}
}
for(int i=0;i<=n;i++)
{
for(int j=i-1,x=2;j>=0;j--,x+=4)
ansx[i]+=c[j]*x*x;
for(int j=i,x=2;j<n;j++,x+=4)
ansx[i]+=c[j]*x*x;
}
for(int i=0;i<=m;i++)
{
for(int j=i-1,x=2;j>=0;j--,x+=4)
ansy[i]+=l[j]*x*x;
for(int j=i,x=2;j<m;j++,x+=4)
ansy[i]+=l[j]*x*x;
}
int Ansx=0,Ansy=0;
long long tmp = 1e18;
for(int i=0;i<=n;i++)
for(int j=0;j<=m;j++)
if(tmp>ansx[i]+ansy[j])
tmp=ansx[i]+ansy[j],Ansx=i,Ansy=j;
cout<<tmp<<endl;
cout<<Ansx<<" "<<Ansy<<endl;
}

Codeforces Round #127 (Div. 1) B. Guess That Car! 扫描线的更多相关文章

  1. Codeforces Round #127 (Div. 1) E. Thoroughly Bureaucratic Organization 二分 数学

    E. Thoroughly Bureaucratic Organization 题目连接: http://www.codeforces.com/contest/201/problem/E Descri ...

  2. Codeforces Round #127 (Div. 1) D. Brand New Problem 暴力dp

    D. Brand New Problem 题目连接: http://www.codeforces.com/contest/201/problem/D Description A widely know ...

  3. Codeforces Round #127 (Div. 1) C. Fragile Bridges dp

    C. Fragile Bridges 题目连接: http://codeforces.com/contest/201/problem/C Description You are playing a v ...

  4. Codeforces Round #127 (Div. 1) A. Clear Symmetry 打表

    A. Clear Symmetry 题目连接: http://codeforces.com/contest/201/problem/A Description Consider some square ...

  5. Codeforces Round #127 (Div. 2)

    A. LLPS 长度最大10,暴力枚举即可. B. Brand New Easy Problem 枚举\(n\)的全排列,按题意求最小的\(x\),即逆序对个数. C. Clear Symmetry ...

  6. Codeforces Round #366 (Div. 2) ABC

    Codeforces Round #366 (Div. 2) A I hate that I love that I hate it水题 #I hate that I love that I hate ...

  7. Codeforces Round #354 (Div. 2) ABCD

    Codeforces Round #354 (Div. 2) Problems     # Name     A Nicholas and Permutation standard input/out ...

  8. Codeforces Round #368 (Div. 2)

    直达–>Codeforces Round #368 (Div. 2) A Brain’s Photos 给你一个NxM的矩阵,一个字母代表一种颜色,如果有”C”,”M”,”Y”三种中任意一种就输 ...

  9. cf之路,1,Codeforces Round #345 (Div. 2)

     cf之路,1,Codeforces Round #345 (Div. 2) ps:昨天第一次参加cf比赛,比赛之前为了熟悉下cf比赛题目的难度.所以做了round#345连试试水的深浅.....   ...

随机推荐

  1. 通过or注入py脚本

    代码思路 1.主要还是参考了别人的代码,确实自己写的和别人写的出路很大,主要归咎还是自己代码能力待提高吧. 2.将功能集合成一个函数,然后通过*args这个小技巧去调用.函数的参数不是argv的值,但 ...

  2. vue路由-动态路由和嵌套路由

    一.动态路由 我们经常需要把某种模式匹配到的所有路由,全都映射到同个组件.例如,我们有一个 User 组件,对于所有 ID 各不相同的用户,都要使用这个组件来渲染.那么,我们可以在 vue-route ...

  3. 【Educationcal Codeforces Round 21】

    这场edu我原本以为能清真一点…… 后来发现不仅是七题 还有各种奇奇怪怪的骚操作…… A. 随便枚举 #include<bits/stdc++.h> using namespace std ...

  4. VPS性能综合测试(7):服务器压力测试,VPS系统负载测试

    1.可能有的VPS主机使用性能测评工具得出的结果很优秀,但是最终运用到实际生产时却发现VPS主机根本无法承受理论上应该达到的流量压力,这时我们就不得不要怀疑VPS商是不是对VPS主机的参数进行了“篡改 ...

  5. js-xlsx操作excel表格

    1导入与导出功能实现 <!DOCTYPE html> <html lang="en"> <head> <meta charset=&quo ...

  6. js中常用的数组方法

    在数组的尾部增加或删除某个元素:push() 和 pop() push() : 在数组的尾部追加一个或多个元素,并返回数组的长度 pop():在数组的尾部删除一个元素,并返回被删除项 var arr ...

  7. supervisor error: <class 'socket.error'>, [Errno 110]

    supervisorctr status报错 error: <class 'socket.error'>, [Errno 110] Connection timed out: file: ...

  8. js获取鼠标的位置

    <!doctype html><html><head><meta charset="utf-8"><title>获取鼠标 ...

  9. 【python】pip的使用

    来源:http://www.ttlsa.com/python/how-to-install-and-use-pip-ttlsa/ pip是用来安装python相关的包的.使用参数如下: # pip - ...

  10. 基于UDP套接字编程实例

    data.h #ifndef DATA_H #define DATA_H #include <stdio.h> #include <string.h> #include < ...