分析:位于同一条主对角线上元素满足i-j相同,位于同一条副对角线上的元素满足i+j相同。而两个象的位置满足i + j的奇偶性不同即可。
#include<stdio.h>
#include<string.h>
#define N 2005
typedef __int64 LL;
LL a[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",&a[i][j]);
L[i+j] += a[i][j];
R[i-j+n] += a[i][j];
}
}
int x1 = 1, x2 = 1, y1 = 1, y2 = 2; //初始化点x1, x2为 (1, 1)(1,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] - a[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;
}