Array-09. The local maximum value (15) time limit for the matrix is limited by MS Memory limit 65536 KB code length limit 8000 B award Program StandardAuthor Xu Jianchun (Zhejiang University)
Given the integer matrix A of the M row N column, if the non-boundary element of a a[i][j] is greater than the next 4 elements, then the element A[i][j] is the local maximum value of the matrix. The subject requires the full local maxima of the given matrix and its location.
Input format:
The input gives the number of rows m and the number of columns N (3<=m,n<=20) of matrix A in line 1th, and the last M row, each row gives the value of the N elements of a in that row. The numbers are separated by a space.
Output format:
Each line outputs a local maximum value in the format of the element value row number column number, where the row, column number starts with 1. It is required to increment the output by line number, and if the peer has more than 1 local maxima, the row is incremented by column number. If there is no local maximum, output the total number of rows with "None".
Input Sample 1:
4 51 1 1 1 11 3 9 3 11 5 3 5 11 1 1 1 1
Output Example 1:
9 2 35 3 25 3 4
Input Sample 2:
3 51 1 1 1 19 3 9 9 11 5 3 5 1
Output Example 2:
None 3 5
1#include <stdio.h>2#include <math.h>3#include <stdlib.h>4#include <string.h>5 intMain ()6 {7 intM, N, I, J, a[ -][ -], flag =1;8scanf"%d%d", &m, &n);9 for(i =1; I <= m; i++)Ten for(j =1; J <= N; J + +) Onescanf"%d", &a[i][j]); A for(i =2; I < m; i++) - for(j =2; J < N; J + +) - if(A[i][j] > a[i-1][J] && A[i][j] > a[i+1][J] && A[i][j] > a[i][j-1] && A[i][j] > a[i][j+1]) the { -printf"%d%d%d\n", A[i][j], I, j); -Flag =0; - } + if(flag) -printf"None%d%d\n", M, n); + return 0; A}
Array-09. Finding the local maxima of a matrix