题目:http://acm.hdu.edu.cn/showproblem.php?pid=4500
腾讯第二届马拉松3月20日第0场第一题。
水题。枚举。外层加一层0较好计算。
#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <algorithm>
#include <string.h>
using namespace std;
int map[30][30];
int disx[4] = {-1,0,1,0};
int disy[4] = {0,1,0,-1};
int main()
{
#ifndef ONLINE_JUDGE
freopen("in.txt","r",stdin);
#endif
int n,m;
while(scanf(" %d %d",&n,&m)!=EOF)
{
if(n + m == 0)
{
break;
}
memset(map,0,sizeof(map));
for(int i=1;i<=n;i++)
{
for(int j=1;j<=m;j++)
{
scanf(" %d",&map[i][j]);
}
}
int max = -0x3f3f3f3f;
int maxR,maxC;
for(int i=1;i<=n;i++)
{
for(int j=1;j<=m;j++)
{
int ans = 0;
for(int k=0;k<4;k++)
{
int tempx = i + disx[k];
int tempy = j + disy[k];
//性别不同
if((map[i][j]<0 && map[tempx][tempy]>0) || (map[i][j]>0 && map[tempx][tempy]<0))
{
ans += abs(map[tempx][tempy]);
}
else
{
ans -= abs(map[tempx][tempy]);
}
}
if(ans > max)
{
max = ans;
maxR = i,maxC = j;
}
}
}
printf("%d %d %d\n",maxR,maxC,max);
}
return 0;
}