Computers and Technology

A team of young programmers was playing with the contents of a two-dimensional matrix in a systematic manner and suddenly team members found an interesting thing. They observed that the contents are getting arranged in an increasing order when one moves either in a row (left to right) or in a column (top to bottom). Thus they decided to implement the systematic procedure which they followed while playing. They developed a document first and then share it with other teams too so that they can also verify the said observation.
Here’s what they shared:
Let A be a square n×n matrix of integers.
Rows/columns with lower indices have to be processed first.
The process has to be repeated alternatively on rows and columns.
Overall the processing sequence to be followed is row0,column0,row1,column1,…rown−1,c olumnn−1.
If we are at ith row, then we have to work with each column at a time from 0 to n−1 of this row. For any jth column, swap A[i][j] with the minimum of all the elements which are present in a column with index j and rows from indices i to n−1.
If we are at jth column, then we have to work with each row at a time from 0 to n−1 of this column. For any ith row, swap A[i][j] with the minimum of all the elements which are present in a row with index i and columns with indices j to n−1.
Let you, being a member of one of the senior teams, received the same. To do a bit of analysis, you decided to proceed with the implementation and also to keep a count on the total number of swaps.
Input:
Line 1 contains an integer N, the size of the square matrix.
Line 2 contains N∗N integers separated by space. These are the contents of a square matrix in row-major order.
Output:
Line 1 is an integer giving the total number of swaps.
Line 2 is space separated N∗N integers sequence. These are the final contents of a square matrix in row-major order.
Sample Input:
3
19 28 39 21 2 11 22 12 37
Sample Output:
8
2 11 19 12 22 37 21 28 39
EXPLANATION:
The array contents (listed in row-major order) get updated in the following manner after processing each row/column completely:
19 28 39 21 2 11 22 12 37
19 2 11 21 28 39 22 12 37
2 19 11 21 28 39 12 22 37
2 19 11 12 22 37 21 28 39
2 11 19 12 22 37 21 28 39
Language to be used - C/C++

answer
Answers: 2

Other questions on the subject: Computers and Technology

image
Computers and Technology, 21.06.2019 22:00, richellemjordan
Draw the hierarchy chart and design the logic for a program that calculates service charges for hazel's housecleaning service. the program contains housekeeping, detail loop, and end-of-job modules. the main program declares any needed global variables and constants and calls the other modules. the housekeeping module displays a prompt for and accepts a customer's last name. while the user does not enter for the name, the detail loop accepts the number of bathrooms and the number of other rooms to be cleaned. the service charge is computed as $40 plus $15 for each bathroom and $10 for each of the other rooms. the detail loop also displays the service charge and then prompts the user for the next customer's name. the end-of-job module, which executes after the user enters the sentinel value for the name, displays a message that indicates the program is complete.
Answers: 2
image
Computers and Technology, 22.06.2019 15:10, AleciaCassidy
Consider a direct-mapped cache with 216 words in main memory. the cache has 16 blocks of 8 words each. it is a word-addressable computer (rather than a byte-addressable computer which we normally discuss). (a) how many blocks of main memory are there? (b) what is the format of a memory address as seen by the cache, that is, what are the sizes of the tag, cache block, and block offset fields (if they apply)? (c) to which cache block will the memory reference db6316 map?
Answers: 1
image
Computers and Technology, 23.06.2019 04:31, hargunk329
Q13 what function does a security certificate perform? a. creates user accounts b. scrambles data c. identifies users d. creates password policies e. provides file access
Answers: 1
image
Computers and Technology, 23.06.2019 21:10, jmolina57
Asample of 200 rom computer chips was selected on each of 30 consecutive days, and the number of nonconforming chips on each day was as follows: 8, 19, 27, 17, 38, 18, 4, 27, 9, 22, 30, 17, 14, 23, 15, 14, 12, 20, 13, 18, 14, 20, 9, 27, 30, 13, 10, 19, 12, 26. construct a p chart and examine it for any out-of-control points. (round your answers to four decimal places.)
Answers: 2
Do you know the correct answer?
A team of young programmers was playing with the contents of a two-dimensional matrix in a systemati...

Questions in other subjects:

Konu
Mathematics, 22.01.2022 02:20
Konu
English, 22.01.2022 02:20