小Q系列故事――�丝的逆袭 HDU 4500
水题:
1 #include<iostream> 2 #include<stdio.h> 3 #include<algorithm> 4 #include<math.h> 5 using namespace std; 6 int main() 7 { 8 int n,m,i,j,a[25][25],b[25][25],max1,left,right; 9 while(scanf("%d%d",&n,&m)!=EOF) 10 { 11 if(n==0&&m==0) 12 break; 13 for(i=1;i<=n;i++) 14 for(j=1;j<=m;j++) 15 { 16 scanf("%d",&a[i][j]); 17 b[i][j]=0; 18 } 19 max1=-1000005; 20 for(i=1;i<=n;i++) 21 for(j=1;j<=m;j++) 22 { 23 if(i-1>=1) 24 { 25 if((a[i][j]>0&&a[i-1][j]>0)||(a[i][j]<0&&a[i-1][j]<0)) 26 b[i][j]-=abs(a[i-1][j]); 27 else 28 b[i][j]+=abs(a[i-1][j]); 29 } 30 if(i+1<=n) 31 { 32 if((a[i][j]>0&&a[i+1][j]>0)||(a[i][j]<0&&a[i+1][j]<0)) 33 b[i][j]-=abs(a[i+1][j]); 34 else 35 b[i][j]+=abs(a[i+1][j]); 36 } 37 if(j-1>=1) 38 { 39 if((a[i][j]>0&&a[i][j-1]>0)||(a[i][j]<0&&a[i][j-1]<0)) 40 b[i][j]-=abs(a[i][j-1]); 41 else 42 b[i][j]+=abs(a[i][j-1]); 43 } 44 if(j+1<=m) 45 { 46 if((a[i][j]>0&&a[i][j+1]>0)||(a[i][j]<0&&a[i][j+1]<0)) 47 b[i][j]-=abs(a[i][j+1]); 48 else 49 b[i][j]+=abs(a[i][j+1]); 50 } 51 if(b[i][j]>max1) 52 { 53 max1=b[i][j]; 54 left=i; 55 right=j; 56 } 57 58 } 59 printf("%d %d %d ",left,right,max1); 60 } 61 return 0; 62 }