Advertisement
Guest User

Untitled

a guest
Feb 16th, 2018
108
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.42 KB | None | 0 0
  1. import java.io.*;
  2.  
  3. public class LargesAreaInMatrix {
  4. public static void main(String[] args) throws Exception {
  5. BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
  6. String[] tokens = in.readLine().split(" ");
  7. int a = Integer.parseInt(tokens[0]);
  8. int b = Integer.parseInt(tokens[1]);
  9. int[][] array=new int[a][b];
  10. for(int i=0;i<a;i++){
  11. String[] numbers = in.readLine().split(" ");
  12. for(int j=0;j<b;j++){
  13. array[i][j]=Integer.parseInt(numbers[j]);
  14. }
  15. }
  16. int maxSum[][]=new int[1024][1];
  17. for(int i=0;i<1024;i++){
  18. maxSum[i][0]=Integer.MIN_VALUE;
  19. }
  20. int currentSum[][]=new int[1024][1];
  21. for(int i=1;i<a-1;i++){
  22. for(int j=1;j<b-1;j++){
  23. int aray=array[i][j];
  24. currentSum[aray][0]+=neighbours(array,i,j);
  25. if(maxSum[aray][0]<=currentSum[aray][0]){
  26. maxSum[aray][0]=currentSum[aray][0];
  27. }
  28. }
  29. }
  30. int maxxSum=Integer.MIN_VALUE;
  31. for(int i=0;i<1024;i++){
  32. if(maxxSum<=maxSum[i][0]){
  33. maxxSum=maxSum[i][0];
  34. }
  35. }
  36. System.out.println(maxxSum);
  37. }
  38. public static int neighbours(int[][] arraySum,int row,int col){
  39. int sum=0;
  40. if(arraySum[row][col]==arraySum[row+1][col]){
  41. sum++;
  42. }
  43. if(arraySum[row][col]==arraySum[row][col+1]){
  44. sum++;
  45. }
  46. if(arraySum[row][col]==arraySum[row-1][col]){
  47. sum++;
  48. }
  49. if(arraySum[row][col]==arraySum[row][col-1]){
  50. sum++;
  51. }
  52. return sum;
  53. }
  54.  
  55. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement