Gargari and Bishops
time limit per test

3 seconds

memory limit per test

256 megabytes

input

standard input

output

standard output

Gargari is jealous that his friend Caisa won the game from the previous problem. He wants to prove that he is a genius.

He has a n × n chessboard. Each cell of the chessboard has a number written on it. Gargari wants to place two bishops on the chessboard in such a way that there is no cell that is attacked by both of them. Consider a cell with number x written on it, if this cell is attacked by one of the bishops Gargari will get x dollars for it. Tell Gargari, how to place bishops on the chessboard to get maximum amount of money.

We assume a cell is attacked by a bishop, if the cell is located on the same diagonal with the bishop (the cell, where the bishop is, also considered attacked by it).

Input

The first line contains a single integer n (2 ≤ n ≤ 2000). Each of the next n lines contains n integers aij (0 ≤ aij ≤ 109) — description of the chessboard.

Output

On the first line print the maximal number of dollars Gargari will get. On the next line print four integers: x1, y1, x2, y2 (1 ≤ x1, y1, x2, y2 ≤ n), where xi is the number of the row where the i-th bishop should be placed, yi is the number of the column where the i-th bishop should be placed. Consider rows are numbered from 1 to n from top to bottom, and columns are numbered from 1 to n from left to right.

If there are several optimal solutions, you can print any of them.

Sample test(s)
input
4
1 1 1 1
2 1 1 0
1 1 1 0
1 0 0 1

output
12
2 2 3 2

题意:给出一个n*n的棋盘,每个方格中有一个非负整数,在棋盘中放两个象,使得这两个象既不会互相攻击,攻击范围也不能有重合,并且在这两个象攻击范围内的格子中的值的总和最大,输出总和和两个象的位置坐标。如果一个格子和象在一条对角线上,则这个格子就在这个象的攻击范围内。
分析:简单分析可以得出:位于同一条主对角线上元素Map[i][j]满足i-j相同,位于同一条副对角线上的元素Map[i][j]满足i+j相同。如果两个象不会互相攻击,且攻击范围没有重合,那么这两个象的坐标x1+y1和x2+y2的奇偶性一定不同。所以我们只需预处理出每条对角线上的元素之和,然后更新即可。具体见代码。
#include<cstdio>
#include<cstring>
const int N = 2005;
typedef long long LL;
LL Map[N][N]; //棋盘
LL L[N*2]; //副对角线元素之和
LL R[N*2]; //主对角线元素之和
int main()
{int n;while(~scanf("%d",&n)) {memset(L, 0, sizeof(L));memset(R, 0, sizeof(R));for(int i = 1; i <= n; i++) {for(int j = 1; j <= n; j++) {scanf("%I64d",&Map[i][j]);L[i+j] += Map[i][j]; //同一条副对角线i+j相同R[i-j+n] += Map[i][j]; //同一条主对角线i-j相同}}int x1 = 1, x2 = 1, y1 = 1, y2 = 2;LL max1 = 0, max2 = 0;for(int i = 1; i <= n; i++) {for(int j = 1; j <= n; j++) {LL tmp = L[i+j] + R[i-j+n] - Map[i][j];if((i+j) % 2 == 0 && tmp > max1) {max1 = tmp;x1 = i;y1 = j;}if((i + j) % 2 == 1 && tmp > max2) {max2 = tmp;x2 = i;y2 = j;}}}printf("%I64d\n", max1 + max2);printf("%d %d %d %d\n", x1, y1, x2, y2);}return 0;
}

CodeForce 463C Gargari and Bishops(贪心+暴力)相关推荐

  1. codeforces 463C. Gargari and Bishops 解题报告

    题目链接:http://codeforces.com/contest/463/problem/C 题目意思:要在一个 n * n 大小的棋盘上放置两个bishop,bishop可以攻击的所有位置是包括 ...

  2. codeforces Gargari and Bishops(很好的暴力)

    1 /* 2 题意:给你一个n*n的格子,每一个格子都有一个数值!将两只bishops放在某一个格子上, 3 每一个bishop可以攻击对角线上的格子(主对角线和者斜对角线),然后会获得格子上的 4 ...

  3. hdu3697(贪心+暴力)

    题意: 一个人要选课,现在给出每门课的选课开始时间和选课截止时间,这个人会每隔5分钟选一次课,问他最多可以选多少门课. 思路: 我们把没门课按结束时间从小到大排序,结束时间相同按开始时间从小到大排序, ...

  4. P2354,jzoj3757-[NOI2014]随机数生成器【贪心,暴力】

    正题 题目链接:https://www.luogu.com.cn/problem/P2354 解题思路 以1∼n∗m1\sim n*m1∼n∗m的数字组成的n∗mn*mn∗m的矩阵,求一条路径使得路径 ...

  5. 夺宝奇兵 (优先队列 + 贪心 + 暴力枚举)

    题目描述 wls 所在的王国有 n 个居民(不包括 wls),他们共有 m 件神奇的宝物. 对于第  件宝物,wls 可以花费  的金币把它从原来的主人那里买过来. 请问 wls最少要准备多少金币,才 ...

  6. hdu2037 今年暑假不AC(贪心||暴力)

    http://acm.hdu.edu.cn/showproblem.php?pid=2037 题意:中文题不解释.首先是尽人皆知的贪心,用烂了.刚开始入门时候不懂,就跟着人模仿.今天(2016/10/ ...

  7. hdu-5583 Kingdom of Black and White(数学,贪心,暴力)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5583 Kingdom of Black and White Time Limit: 2000/1000 ...

  8. hiho 1615 矩阵游戏II [Offer收割]编程练习赛33 Problem A 贪心暴力

    把每列取反后所能获得的收益记录下来,然后排序,从高到低一对对的取,大于0就算上. #include <iostream> #include <stdio.h> #include ...

  9. Codeforces Round #264 (Div. 2) 解题报告

    Source:  http://codeforces.com/contest/463 打得比较差..第三题想写nlgn的,结果调了很久又wa,以为写挫,过了很久发现做法有问题..最后两题惨淡收场.第四 ...

最新文章

  1. linux路由介绍,Linux的路由表详细介绍
  2. hdu 1228-A+B
  3. java 集合 延迟加载_java-如何测试延迟加载的JPA集合是否已初始化?
  4. java接口的定义与实现实验报告,赶紧收藏备战金三银四!
  5. 修改2440里面的FriendlyARM
  6. 深度学习中的专业英语词汇(by Youki)
  7. andriod 自定义来电界面功能
  8. RestClientException: Could not extract response: no suitable HttpMessageConverter found for response
  9. CleanMyMac X断网激活码免费共享教程免费分享
  10. 医院信息系统培训心得
  11. fild与fmul的问题
  12. 银行卡Bin和Logo
  13. BZOJ3161 : 孤舟蓑笠翁
  14. 《异常点检测》 - 第十章阅读记录 - 离散序列的异常点检测
  15. 黑苹果双系统时间不一致_黑苹果与Windows系统时间不对(不同步)的解决办法...
  16. 4. 假设一年期定期利率为 3.25%,计算一下需要过多少年,一万元的一年定期存款连本带息能翻番?
  17. AB test | 学习笔记
  18. 织梦图集php,织梦怎么为新图集页面增加图片下载功能
  19. 基于matlab的禁止无功补偿,基于MATLAB的TSC-TCR型静止无功补偿器仿真研究.zip
  20. 【干货书】Python中的商业分析概念、技术和应用的数据挖掘

热门文章

  1. 神策数据加入猿团程序员大牛卡,创客大礼包助力开发。
  2. Java GUI:将JPanel添加进JScrollPane
  3. 蓝桥杯 十进制数转八进制数
  4. redis开启外网访问
  5. 关于meta的各种用处以及移动端的常见问题
  6. SESSION存储于redis(CI3)
  7. 丁钧:移动,未来的王
  8. OSPF 形成邻居 关系的条件
  9. 杭州中联高级技术培训中心CCNA实验手册
  10. reservation for talk at Stanford