题目来源:http://acm.hdu.edu.cn/showproblem.php?pid=4500
#include <iostream>
#include <cstdio>
#include <cstring>
#include <climits>
using namespace std;
const int MAXN = 25;
int fabs(int a)
{
return a > 0 ? a : (-a);
}
int Find_Abs(int a, int b)
{
if(a * b < 0)
return fabs(b);
else if(a * b > 0)
return -fabs(b);
else
return 0;
}
int main()
{
int Graph[MAXN][MAXN];
int dir[4][2] = {{-1, 0}, {0, -1}, {1, 0}, {0, 1}};
int CurVal;
int i, j, k, xpos, ypos;
int MaxNum;
int row, col;
while(scanf("%d%d", &row, &col) && (row + col))
{
memset(Graph, 0, sizeof(Graph));
for(i = 1; i <= row; ++i)
for(j = 1; j <= col; ++j)
scanf("%d", &Graph[i][j]);
MaxNum = INT_MIN , xpos = 1, ypos = 1;
for(i = 1; i <= row; ++i)
{
for(j = 1; j <= col; ++j)
{
CurVal = 0;
for(k = 0; k < 4; ++k)
{
int x = i + dir[k][0];
int y = j + dir[k][1];
if(x < 1 || x > row || y < 1 || y > col)
continue ;
CurVal += Find_Abs(Graph[i][j], Graph[x][y]);
}
if(CurVal > MaxNum)
{
MaxNum = CurVal;
xpos = i, ypos = j;
}
}
}
printf("%d %d %d\n", xpos, ypos, MaxNum);
}
return 0;
}