Let’s Go！！！

hdu4500 小Q系列故事——屌丝的逆袭

#include <iostream>
#include <string.h>

using namespace std;

#define MAXN 100 + 10

const int INF = (~0U >> 1);

int c[MAXN][MAXN];
int array[MAXN][MAXN];
int dir[4][2] =
{
0, -1, -1, 0, 0, 1, 1, 0
};

void input()
{
int n, m;

while (cin >> n >> m, n + m)
{
for (int i = 0; i < n; i++)
{
for (int j = 0; j < m; j++)
{
cin >> array[i][j];
}
}

memset(c, 0, sizeof(c));

int mx = -INF, p1 = 0, p2 = 0;

for (int i = 0; i < n; i++)
{
for (int j = 0; j < m; j++)
{
for (int k = 0; k < 4; k++)
{
int x = i + dir[k][0];
int y = j + dir[k][1];

if (x >= 0 && x < n && y >= 0 && y < m)
{
if (array[i][j] * array[x][y] > 0)
{
c[i][j] -= abs((int)array[x][y]);
}
else
{
c[i][j] += abs((int)array[x][y]);
}
}
}

if (c[i][j] > mx) //注意比较
{
mx = c[i][j];
p1 = i;
p2 = j;
}
else if (c[i][j] == mx)
{
if (i < p1)
{
p1 = i;
p2 = j;
}
else if (i == p1)
{
if (j < p2)
{
p2 = j;
}
}
}
}
}

cout << p1 + 1 << ' ' << p2 + 1 << ' ' << mx << endl;
}
}

int main()
{
input();
return 0;
}


03-22 683

05-24 934

04-30 1073

05-08 1819

03-22 318

03-23 947

03-21 625

03-30 965

05-27 830

10-07 614