标签:row 相同 tput 上下左右 评分 多个 als iostream 存在
2017-07-14 18:13:35
2 3 5 -4 3 -6 3 7 0 0Sample Output
1 2 11
#include <iostream> #include <cmath> using namespace std; int main() { int N,M; while(cin >> N >> M && (N!=0)&&(M!=0)) { int **a = new int* [N+2]; int ** b = new int* [N+2]; for(int i = 0 ; i < N+2; i++) { a[i] = new int[M+2]; b[i] = new int[M+2]; } for(int i = 0 ; i <= N+1 ; i++) { for(int j = 0 ; j <= M+1 ; j++) { if(i == 0 || j == 0 ||i == N+1 || j == M+1) { a[i][j] = 0; } else { cin >> a[i][j]; } } } for(int i = 0 ; i <= N+1; i++) for(int j = 0 ; j <= M+1 ; j++) b[i][j] = 0; for(int i = 1 ; i <= N; i++) { for(int j = 1 ; j <= M ; j++) { int up = a[i-1][j],down = a[i+1][j], left = a[i][j-1],right = a[i][j+1]; if(a[i][j] > 0) { int tmp = 0; if(up > 0) { tmp -= abs(up); } else { tmp += abs(up); } if(down > 0) { tmp -= abs(down); } else { tmp += abs(down); } if(left > 0) { tmp -= abs(left); } else { tmp += abs(left); } if(right > 0) { tmp -= abs(right); } else { tmp += abs(right); } b[i][j]=tmp; } else if(a[i][j] < 0) { int tmp = 0; if(up > 0) { tmp += abs(up); } else { tmp -= abs(up); } if(down > 0) { tmp += abs(down); } else { tmp -= abs(down); } if(left > 0) { tmp += abs(left); } else { tmp -= abs(left); } if(right > 0) { tmp += abs(right); } else { tmp -= abs(right); } b[i][j] = tmp; } else return 1; } } int maxcharm = 0; int tagi,tagj; for(int i = 1 ; i <= N ; i++) { for(int j = 1 ; j <= M ; j++) { if(b[i][j] != 0) if(maxcharm < b[i][j]) { tagi = i; tagj = j; maxcharm = b[i][j]; } } } cout << tagi <<" "<< tagj <<" "<<maxcharm<<endl; } return 0; }
标签:row 相同 tput 上下左右 评分 多个 als iostream 存在
原文地址:http://www.cnblogs.com/ilovelianghui/p/7171816.html