07: matrix return-to-zero subtraction sequence and 07 matrix return-to-zero Subtraction

Source: Internet
Author: User

07: matrix return-to-zero subtraction sequence and 07 matrix return-to-zero Subtraction
07: matrix zeroth subtraction sequence and

  • View
  • Submit
  • Statistics
  • Question
Total time limit:
1000 ms
 
Memory limit:
65536kB
Description

Given a matrix of n * n (3 <=n <= 100, all element values are non-negative integers ). This matrix can be converted into a 1*1 matrix by implementing the following process (n-1. Each process is as follows:

First, return to zero for the matrix: that is, all elements in each row are subtracted from the minimum value of the row based on the original value to ensure that the value after subtraction is still a non-negative integer, the value of at least one element in this row is 0.

Then, return to zero for the matrix: that is, for all elements in each column, the minimum value of the column is subtracted from the original value to ensure that the value after subtraction is still a non-negative integer, the value of at least one element in this column is 0.

Then, subtract the matrix: Delete the second and second columns of the n * n matrix to convert it into a (n-1) * (n-1) matrix.

In the next process, the above process is implemented for the (n-1) * (n-1) matrix generated. Obviously, after (n-1) the above process, the n * n matrix will be converted into a 1*1 matrix.

Request the value of the element in the second column of the Second row before each reduction.



Input
The first line is an integer n.
Next n rows, each row has n positive integers, which describe the entire matrix. Two Adjacent integers are separated by a single space.
Output
The output is n rows, and the integers on each row are the values of the elements located in the second column of the Second row before each reduction in the Matrix to zero.
Sample Input
31 2 32 3 43 4 5
Sample output
300

1 # include <iostream> 2 # include <iomanip> 3 # include <cmath> 4 # include <cstring> 5 using namespace std; 6 int a [200] [200]; 7 int main () {8 int I; 9 int j; 10 int k; 11 int l; 12 int m; 13 int n; 14 int ma; 15 int n1; 16 cin> n; 17 for (I = 1; I <= n; I ++) 18 for (j = 1; j <= n; j ++) 19 cin> a [I] [j]; 20 n1 = n; // Save the number of rows and columns in the matrix. 21 for (k = 1; k <= n1; k ++) // The n1 22 {23 cout <a [2] [2] <endl; // output the 24 for (I = 1; I <= n; I ++) 25 {26 ma = a [I] [1]; // Save the first value of each line to prevent null values 27 for (j = 2; j <= n; j ++) 28 if (a [I] [j] <ma) 29 ma = a [I] [j]; // obtain the minimum value of 30 for (j = 1; j <= n; j ++) 31 a [I] [j] = a [I] [j]-ma; // trim each row by 32} 33 for (j = 1; j <= n; j ++) // perform 34 {35 ma = a [1] [j] for each column; // Similarly, save the first value of the column, prevent null values 36 for (I = 2; I <= n; I ++) 37 if (a [I] [j] <ma) 38 ma = a [I] [j]; 39 for (I = 1; I <= n; I ++) 40 a [I] [j] = a [I] [j]-ma; 41} 42 for (I = 2; I <n; I ++) 43 for (j = 1; j <= n; j ++) 44 a [I] [j] = a [I + 1] [j]; 45 for (j = 2; j <n; j ++) 46 for (I = 1; I <= n; I ++) 47 a [I] [j] = a [I] [j + 1]; // Delete 48 n --; 49} 50 return 0; 51}

 

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.