Description
Input
Output
Sample Input
Sample Output
#include <stdio.h>
#include <math.h>
int main()
{
int N,M,i,j,a[21][21],b[21][21];//a数组用来存放对应员工的魅力值,b数组用来存放每个位置的得分
while(scanf("%d%d",&N,&M)!=EOF)
{
if(N==0&&M==0)
break;
for(i=0; i<=M; i++)
a[1][i]=0;
for(j=0; j<=N; j++)
a[j][1]=0;
for(i=1; i<=N; i++)
for(j=1; j<=M; j++)
scanf("%d",&a[i][j]);
for(i=1; i<=N; i++)
for(j=1; j<=M; j++)
{
if(a[i][j]*a[i-1][j]<=0)
b[i][j]=fabs(a[i-1][j]);
else
b[i][j]=-1*(fabs(a[i-1][j]));
if(a[i][j]*a[i+1][j]<=0)
b[i][j]+=fabs(a[i+1][j]);
else
b[i][j]+=-1*(fabs(a[i+1][j]));
if(a[i][j]*a[i][j-1]<=0)
b[i][j]+=fabs(a[i][j-1]);
else
b[i][j]+=-1*(fabs(a[i][j-1]));
if(a[i][j]*a[i][j+1]<0)
b[i][j]+=fabs(a[i][j+1]);
else
b[i][j]+=-1*(fabs(a[i][j+1]));
}
int max=b[1][1];
for(i=1; i<=N; i++)
for(j=1; j<=M; j++)
if(b[i][j]>max)
max=b[i][j];
for(i=1; i<=N; i++)
for(j=1; j<=M; j++)
if(b[i][j]==max)
{
printf("%d %d %d\n",i,j,max);
break;
}
}
}
竟赛题?