Array-09. Finding the local maxima of a matrix

Source: Internet
Author: User

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.