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. xrange和range的区别

    >>> print type(range(5)) <type 'list'> >>> print type(xrange(5)) <type 'x ...

  2. Xmind 8 update5 破解

    Step 1. Download XMind Step 2. Run XMind at least once after installation, xmind will init the confi ...

  3. linux平台学x86汇编语言学习集合帖

    linux平台学x86汇编语言学习集合帖 linux平台学x86汇编(一):https://blog.csdn.net/shallnet/article/details/45543237 linux平 ...

  4. Yii 1.1.17 四、属性标签、AR类增删改查、使用上传类与扩展第三方类库

    一.属性标签与规则设置 当进入网站页面,将会读数据库返回信息到视图上.那么,现在定义模型中的属性在视图标签上的显示, 也就是模型属性到前台标签的映射 // 定义模型属性到前台标签的映射 public ...

  5. 10 个打造 React.js App 的最佳 UI 框架

    10 个打造 React.js App 的最佳 UI 框架 在本文中,我们将分享一些助你打造 React.js App 最佳的 UI 框架.它们具备你所需要的基本 React 组件,以及易用的 API ...

  6. ie6下面不支持!important的处理方法

    例子: #box {      color:red !important;      color:blue;  } 这个例子应该是大家经常见到的important的用法了,在IE6环境下,这行字是蓝色 ...

  7. javascript方法--apply()

    今天琢磨了一下apply,以前对这个方法觉得比较懵,今天一琢磨确实觉得挺好玩的. 一开始把MDN的apply文档看了一遍,感觉不是很理解,而且有一些东西也是知道但是比较模糊,所以还是一步一步来,不懂查 ...

  8. jdbc连接远程数据库进行操作

    链接远程数据库的时候,要把获得链接的url进行修改 1 package com.test; import java.sql.Connection; import java.sql.DriverMana ...

  9. python 作业

    Linux day01 计算机硬件知识整理 作业要求:整理博客,内容如下 编程语言的作用及与操作系统和硬件的关系 应用程序->操作系统->硬件 cpu->内存->磁盘 cpu与 ...

  10. centos安装VNC的方法

    https://help.aliyun.com/knowledge_detail/6698160.html(阿里云官方文档,但是官方文档有些地方是错的,我更正了下) ----------------- ...