Analysis: Water problem, pay attention to the calculation of a position of the score of his own does not count, plus and minus are absolute values (at first it was also misunderstood).
#include <iostream> #include <cmath>using namespace Std;int a[25][25];int main () {int I,j,n,m;int maxv,maxi, Maxj,tmp;while (cin>>n>>m && n+m) {for (i=0;i<n;i++) for (j=0;j<m;j++) cin>>a[i][j]; Maxv=-100000000;for (i=0;i<n;i++) for (j=0;j<m;j++) {tmp=0;if (i>0) {if (a[i][j]*a[i-1][j]<0) Tmp+=abs (a[ I-1][J]); Elsetmp-=abs (A[i-1][j]);} if (j>0) {if (a[i][j]*a[i][j-1]<0) tmp+=abs (a[i][j-1]); Elsetmp-=abs (A[i][j-1]);} if (i<n-1) {if (a[i][j]*a[i+1][j]<0) Tmp+=abs (A[i+1][j]); Elsetmp-=abs (A[i+1][j]);} if (j<m-1) {if (a[i][j]*a[i][j+1]<0) Tmp+=abs (a[i][j+1]); Elsetmp-=abs (a[i][j+1]);} if (maxv<tmp) {maxv=tmp;maxi=i;maxj=j;}} cout<<maxi+1<< "<<maxj+1<<" "<<MAXV<<ENDL;} return 0;}
HDU ACM 4500 Small Q series Story-the reverse of the cock silk