C Programming Language (Code With C Programming Language) Problem Title : Visible Trees There is a legend about a magical park with N × N trees. The trees are positioned in a square grid with N rows (numbered from 1 to N from north to south) and N columns (numbered from 1 to N from west to east). The height (in metres) of each tree is an integer between 1 and N × N, inclusive. Magically, the height of all trees is unique. Bunga is standing on the northmost point of the park and wants to count the number of visible trees for each Column. Similarly, Lestari is standing on the westmost point of the park and wants to count the number of visible trees for each Row. A tree X is visible if all other trees in front of the tree X are shorter than the tree X. For example, let N = 3 and the height (in metres) of the trees are as follows 6 1 8 7 5 3 2 9 4 On the first column, Bunga can see two trees, as the tree on the third row is obstructed by the other trees. On the second column, Bunga can see all three trees. On the third column, Bunga can see only the tree on the first row, as the other trees are obstructed by the tree on the first row. On the first row, Lestari can see two trees, as the tree on the second column is obstructed by the tree on the first column. On the second row, Lestari can see only the tree on the first column, as the other trees are obstructed by the tree on the first column. On the third row, Lestari can see two trees, as the tree on the third column is obstructed by the tree on the second column. Your task is to determine the numbers reported by Bunga and Lestari. Format Input Input begins with a line containing an integer: N (1 ≤ N ≤ 10) representing the number of trees on each row and column. The next N lines each contains N integers representing the height (in metres) of the trees. The jth integer on the ith line is the height of the tree on the ith row and jth column between 1 to N × N, inclusive. It is guaranteed that all trees have different heights. Format Output Output begins with a line containing N integers representing the number of trees visible by Bunga. The jth integer is the number of visible trees on the jth column. The next N lines each contains an integer representing the number of trees visible by Lestari. The integer on the ith line is the number of visible trees on the ith row. Constraints 1 ≤ N ≤ 10 jth integer on the ith line is the height of the tree on the ith row and jth column between 1 to N × N, inclusive It is guaranteed that all trees have different heights Sample Input 1 (Standard Input) 3 6 1 8 7 5 3 2 9 4 Sample Output 1 (Standard Output) 2 3 1 2 1 2 Sample Input 2 (Standard Input) 5 22 1 10 2 17 13 12 20 6 7 14 19 3 15 24 4 11 18 25 9 5 23 21 8 16 Sample Output 2 (Standard Output) 1 4 3 4 2 1 2 3 4 2 2

Computer Networking: A Top-Down Approach (7th Edition)
7th Edition
ISBN:9780133594140
Author:James Kurose, Keith Ross
Publisher:James Kurose, Keith Ross
Chapter1: Computer Networks And The Internet
Section: Chapter Questions
Problem R1RQ: What is the difference between a host and an end system? List several different types of end...
icon
Related questions
Question
100%

C Programming Language (Code With C Programming Language)

Problem Title : Visible Trees

There is a legend about a magical park with N × N trees. The trees are positioned in a square grid with N rows (numbered from 1 to N from north to south) and N columns (numbered from 1 to N from west to east). The height (in metres) of each tree is an integer between 1 and N × N, inclusive. Magically, the height of all trees is unique.

Bunga is standing on the northmost point of the park and wants to count the number of visible trees for each Column. Similarly, Lestari is standing on the westmost point of the park and wants to count the number of visible trees for each Row. A tree X is visible if all other trees in front of the tree X are shorter than the tree X.

For example, let N = 3 and the height (in metres) of the trees are as follows
6 1 8
7 5 3
2 9 4

  • On the first column, Bunga can see two trees, as the tree on the third row is obstructed by the other trees.
  • On the second column, Bunga can see all three trees.
  • On the third column, Bunga can see only the tree on the first row, as the other trees are obstructed by the tree on the first row.
  • On the first row, Lestari can see two trees, as the tree on the second column is obstructed by the tree on the first column.
  • On the second row, Lestari can see only the tree on the first column, as the other trees are obstructed by the tree on the first column.
  • On the third row, Lestari can see two trees, as the tree on the third column is obstructed by the tree on the second column.

Your task is to determine the numbers reported by Bunga and Lestari.

Format Input

Input begins with a line containing an integer: N (1 ≤ N ≤ 10) representing the number of trees on each row and column. The next N lines each contains N integers representing the height (in metres) of the trees. The jth integer on the ith line is the height of the tree on the ith row and jth column between 1 to N × N, inclusive. It is guaranteed that all trees have different heights.

Format Output

Output begins with a line containing N integers representing the number of trees visible by Bunga. The jth integer is the number of visible trees on the jth column. The next N lines each contains an integer representing the number of trees visible by Lestari. The integer on the ith line is the number of visible trees on the ith row.

Constraints

  • 1 ≤ N ≤ 10
  • jth integer on the ith line is the height of the tree on the ith row and jth column between 1 to N × N, inclusive
  • It is guaranteed that all trees have different heights

Sample Input 1 (Standard Input)

3
6 1 8
7 5 3
2 9 4

Sample Output 1 (Standard Output)
2 3 1
2
1
2

Sample Input 2 (Standard Input)

5
22 1 10 2 17
13 12 20 6 7
14 19 3 15 24
4 11 18 25 9
5 23 21 8 16

Sample Output 2 (Standard Output)
1 4 3 4 2
1
2
3
4
2
2

Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 3 steps with 1 images

Blurred answer
Recommended textbooks for you
Computer Networking: A Top-Down Approach (7th Edi…
Computer Networking: A Top-Down Approach (7th Edi…
Computer Engineering
ISBN:
9780133594140
Author:
James Kurose, Keith Ross
Publisher:
PEARSON
Computer Organization and Design MIPS Edition, Fi…
Computer Organization and Design MIPS Edition, Fi…
Computer Engineering
ISBN:
9780124077263
Author:
David A. Patterson, John L. Hennessy
Publisher:
Elsevier Science
Network+ Guide to Networks (MindTap Course List)
Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:
9781337569330
Author:
Jill West, Tamara Dean, Jean Andrews
Publisher:
Cengage Learning
Concepts of Database Management
Concepts of Database Management
Computer Engineering
ISBN:
9781337093422
Author:
Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:
Cengage Learning
Prelude to Programming
Prelude to Programming
Computer Engineering
ISBN:
9780133750423
Author:
VENIT, Stewart
Publisher:
Pearson Education
Sc Business Data Communications and Networking, T…
Sc Business Data Communications and Networking, T…
Computer Engineering
ISBN:
9781119368830
Author:
FITZGERALD
Publisher:
WILEY