直接暴力枚举,分别枚举黑白棋盘中最大的,二者相加即可。
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
using namespace std;
typedef long long ll;
const int maxn = 2005;
int grid[maxn][maxn];
ll a[maxn<<1],b[maxn<<1];
int n;
int main(){
while(~scanf("%d",&n)){
memset(a, 0, sizeof(a));
memset(b, 0, sizeof(b));
for(int i = 1;i <= n;i++)
for(int j = 1;j <= n;j++){
scanf("%d",&grid[i][j]);
a[i+j] += (ll)grid[i][j];
b[i+n-j] += (ll)grid[i][j];
}
int x1 = 0,y1 =0;
ll temp1 = -1;
int jj;
for(int i = 1;i <= n;i++){
for(int j = 1;j <= n;j += 2){
if(i&1)
jj = j+1;
else
jj = j;
ll temp = a[i+jj] + b[i+n-jj] - (ll)grid[i][jj];
if(temp1 < temp){
x1 = i;
y1 = jj;
temp1 = temp;
}
}
}
int x2 = 0,y2 = 0;
ll temp2 = -1;
for(int i = 1;i <= n;i++){
for(int j = 1;j <= n;j += 2){
if(i&1)
jj = j;
else
jj = j+1;
ll temp = temp = a[i+jj] + b[i+n-jj] - (ll)grid[i][jj];;
if(temp2 < temp){
x2 = i;
y2 = jj;
temp2 = temp;
}
}
}
printf("%I64d\n%d %d %d %d\n",temp1+temp2,x1,y1,x2,y2);
}
return 0;
}