2017-07-14 18:13:35
- Writer:pprp
- Introduction: The most basic code to show the idea of a problem
- Test instructions as follows;
- He carefully observed his work environment, found that the entire studio is an n-row m column of the rectangular layout, or because the nature of the cock silk gradually exposed, he also secretly to each colleague in the heart of the Charm value score (for the difference between men and women, the boys are negative integers, all girls are represented by positive integers).
Now, Little Q records all of the data and defines the value of a location:
1. The value of a position is only related to the charm value of the four neighbors around it (for the position to pull over, only consider its existing neighbors);
2, if a location of the neighbor and the location of the host gender is different, then the total score plus the absolute value of the neighbor charm, otherwise subtracted;
3, after the data processing of all surrounding neighbors, the final score is the final score of this position, the higher the score, the better the position;
Now can you help small q to calculate where is the best location? Input inputs contain multiple sets of test data;
The first row of each set of test data contains 2 integers n and m, which indicates that the studio layout is n rows m column;
The next n rows, each line has m integer, the corresponding position of the employee's charm Value data ki, positive integer representation of the female charm value, negative integer indicates the male charm value;
N and m are 0, indicating the end of the input data.
Tec hn ic al sp ec if ic at io n Technicalspecification
N<=20
M<=20
-100<=ki<=100
Output please calculate and export the best position of the line number and the corresponding score, if there are more than the highest score, then the output row number of the smallest, the line number is the same, then compare the column number, only the smallest column number of the only one can be output.
Sample Input2 35-4 3-6 3 70 0
Sample Output1 2 11
#include <iostream>#include<cmath>using namespacestd;intMain () {intn,m; while(Cin >> N >> M && (n!=0) && (m!=0)) { int**a =New int* [n+2]; int* * B =New int* [n+2]; for(inti =0; I < n+2; i++) {A[i]=New int[m+2]; B[i]=New int[m+2]; } for(inti =0; I <= n+1; i++) { for(intj =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(inti =0; I <= n+1; i++) for(intj =0; J <= m+1; J + +) B[i][j]=0; for(inti =1; I <= N; i++) { for(intj =1; J <= M; J + +) { intup = a[i-1][j],down = a[i+1][j], left= a[i][j-1],right = a[i][j+1]; if(A[i][j] >0) { intTMP =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) { intTMP =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; } } intMaxcharm =0; intTagi,tagj; for(inti =1; I <= N; i++) { for(intj =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;}
Vjudge-a-This is a test you will not language simulation