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;
}

转载于:https://www.cnblogs.com/qscqesze/p/5193568.html

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 #506 (Div. 3)

    Codeforces Round #506 (Div. 3) 实习期间事不多,对div3 面向题解和数据编程了一波 A. Many Equal Substrings 题目链接 A题就是找后缀和前缀重合 ...

  3. Codeforces Round #563 (Div. 2)/CF1174

    Codeforces Round #563 (Div. 2)/CF1174 CF1174A Ehab Fails to Be Thanos 其实就是要\(\sum\limits_{i=1}^n a_i ...

  4. 构造 Codeforces Round #302 (Div. 2) B Sea and Islands

    题目传送门 1 /* 2 题意:在n^n的海洋里是否有k块陆地 3 构造算法:按奇偶性来判断,k小于等于所有点数的一半,交叉输出L/S 4 输出完k个L后,之后全部输出S:) 5 5 10 的例子可以 ...

  5. Codeforces Round #696 (Div. 2) (A ~ E)超高质量题解(每日训练 Day.16 )

    整理的算法模板合集: ACM模板 点我看算法全家桶系列!!! 实际上是一个全新的精炼模板整合计划 Codeforces Round #696 (Div. 2) (A ~ E)超高质量题解 比赛链接:h ...

  6. Codeforces Round #712 Div.2(A ~ F) 超高质量题解(每日训练 Day.15 )

    整理的算法模板合集: ACM模板 点我看算法全家桶系列!!! 实际上是一个全新的精炼模板整合计划 Codeforces Round #712 Div.2(A ~ F) 题解 比赛链接:https:// ...

  7. Codeforces Round #701 (Div. 2) A ~ F ,6题全,超高质量良心题解【每日亿题】2021/2/13

    整理的算法模板合集: ACM模板 点我看算法全家桶系列!!! 实际上是一个全新的精炼模板整合计划 目录 A - Add and Divide B - Replace and Keep Sorted C ...

  8. Codeforces Round #700 (Div. 2) D2 Painting the Array II(最通俗易懂的贪心策略讲解)看不懂来打我 ~

    整理的算法模板合集: ACM模板 点我看算法全家桶系列!!! 实际上是一个全新的精炼模板整合计划 整场比赛的A ~ E 6题全,全部题目超高质量题解链接: Codeforces Round #700 ...

  9. Codeforces Round #699 (Div. 2) F - AB Tree(贪心、树上DP)超级清晰,良心题解,看不懂来打我 ~

    整理的算法模板合集: ACM模板 点我看算法全家桶系列!!! 实际上是一个全新的精炼模板整合计划 Codeforces Round #699 (Div. 2) F - AB Tree Problem ...

最新文章

  1. 如何用php实现分页效果
  2. 洛谷 P2163 [SHOI2007]Tree 园丁的烦恼
  3. qq显示服务器连接中0x9a,打开QQ出现0x00008819错误代码的解决方法
  4. LeetCode之Rotate Array
  5. 2.4 表单数据的验证
  6. 使用PHP的“注意:未定义的变量”,“注意:未定义的索引”和“注意:未定义的偏移量”
  7. 性能测试--jmeter中的用户自定义变量【13】
  8. 使用Visual Studio进行单元测试-Part4
  9. esxi6.7.0最新版本下载
  10. win10微信打电话对方听不到你的声音,你能听到对方声音
  11. 人脸识别中怎么区分人脸和照片
  12. python常见ubr前缀的使用与作用
  13. 特斯拉降价也无法阻挡国内新能源汽车厂商前进的步伐
  14. LInux中的atime、mtime和ctime
  15. vue项目技术知识点
  16. ITE EC(IT81202)--- PMC模块手册翻译
  17. 微信小程序实战之快递查询
  18. 被特殊物种序列虚晃一枪的日子
  19. stata回归表格输出
  20. Tomcat 面试题

热门文章

  1. 左倾红黑树的go语言实现
  2. Opencv Python:图片与视频互转
  3. 802.11n关键技术
  4. NSNumber 与 Tagged Pointer
  5. java 24字母_java 时间格式化中的模式字母
  6. Web在jsp页面中生成柱状图,折线图,饼状图
  7. word20161229
  8. Web开发基础——CSS
  9. HTML基础之label标签
  10. JDK8-十大新特性-附demo