您的位置:首页 > 其它

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

2013-12-06 10:19 197 查看
#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;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: