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

Question

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 Answer

1 Rating

Want to see the step-by-step answer?

Check out a sample Q&A here.

Want to see this answer and more?

Experts are waiting 24/7 to provide step-by-step solutions in as fast as 30 minutes!*

*Response times may vary by subject and question complexity. Median response time is 34 minutes for paid subscribers and may be longer for promotional offers.
Tagged in
Engineering
Computer Engineering

Programing

Related Computer Engineering Q&A

Find answers to questions asked by students like you.

Q: A company pays its employees on a weekly basis. The employees are of four types: Salariedemployeesar...

A: Program approach: Import necessary libraries. Create employee class as abstract type Define a metho...

Q: Write a program to understand customer waiting time. A list provides the number of customers that ar...

A: Click to see the answer

Q: Circle the portion of the IP address that would be invalid if it were assigned to a host, and then e...

A: Aim : Circle the portion of the IP address that would be invalid if it were assigned to a host, and ...

Q: Simulation of bank calling system[Problem Description]Using linear list to simulate the bank's queui...

A: Click to see the answer

Q: Hash Search[Problem Description]Design a hash table which the phone number is the key word and can b...

A: The program is written in c

Q: write a program with C language

A: program approach   print the graph         get the maximum value of distribution·         assume a ...

Q: 14. Which statements are true about the following code? (Choose all that apply) 1: interface HasVoca...

A: interface HasVocalCords {                                  //create an interface    public abstract ...

Q: Machine cycle defines a loop process with four major components. Explain why machine cycle is import...

A: Actually, Machine cycle defines a loop process with four major components Fetch -  Decode -  Execut...

Q: Give solution in C++ Language with secreenshoot of each step.

A: #include <iostream>using namespace std;int main(){ double number,score; string color; wh...

Q: // This program demonstrates a unique_ptr pointing to a dynamically allocated array of integers. #in...

A: This program has asked to write a program to demonstrate unique_ptr pointing to a dynamically alloca...

Q: 10.14 LAB: Book information (overriding member functions)   Given main() and a base Book class, d...

A: Actually, program is a executable software that runs on a computer.

Q: Create the above hierarchy as follows” Create Book class having above attributes provide getter, se...

A: public class Book{        //declare data members    private String authorName;    private double cos...

Q: I have a text file and I want  to read it in C++. variables to use: fname, lname , Id nr, Gender and...

A: The C++ program is written with menu driven program from the user where it gets the details of the s...

Q: write code in c++ please

A: The main objective of the program is to write a c++ program that prompts the user to enter an intege...

Q: Which of the following factors does NOT cause the address (virtual or physical) of a specific variab...

A: Option B(Writing a '3' to /proc/sys/vm/drop_caches) is used to free os cache which can change addres...

Q: I want to write c++ program of this ??

A: The C++ program and necessary comments are provided in the program Input text file: Sample output o...

Q: C++: Create a standalone program that performs the tasks below. Start by solving task one and comple...

A: The program is written in c++ The names.txt taken here is: Harry potter 9910230493 Address_harryJohn...

Q: Assume that the 4-digit numbers that are equal to the square of the sum of the numbers divided into ...

A: Code: in c   #include <stdio.h>   int getDigits(int n)//method for breaking the number into ha...

Q: Develop an algorithm and implement First-In-First-Out (FIFO) page replacement algorithm using C/C++....

A: answer  given string :- 11 13 10 14 15 12 11 19 18 16 15 17 14 16 19 21  frame size = 3 (FIFO)   ...

Q: Q.3. Describe different types of computers and their functioning?

A: A machine is most imaginary and handles the various types of user instructions to eventually generat...

Q: Question-1 There are thousands of customers in an ABC Bank who use ATM services. The ABC Bank stores...

A: import java.util.*; public class Solution {       /*Function to find the index of the given element*...

Q: 1. Deveiop a UML Class diagram For Online railway reservation system. 2. Develop a UML. Class diagra...

A: 1. Use Case Diagram The use case diagram is usually referred to as a behavior diagram used to descri...

Q: Here, A is the start node and G is the goal node. h=12 14 11 h=3 h=0 12 h=20 A E G h=18 10 1 2 16 F ...

A: Click to see the answer

Q: 1- It is the Protocol Data Unit (PDU) of layer 3. Select one: a. data b. frame c. packet d. se...

A: 1- It is the Protocol Data Unit (PDU) of layer 3.   Select one:   a. data   b. frame   c. packet   d...

Q: I asked this question last night but Column "Order ID" was missing and found some error such as two ...

A: The query is asking to do the normalization of the given data into different normalization forms.

Q: https://www.bartleby.com/questions-and-answers/implement-the-binomial-tree-using-java-generic-progra...

A: BinoNode.java import java.util.*; class BinoNode { int data; int numNodes; BinoNode arr[];  public B...

Q: How to write a valid standard php code block?

A: Please find the answer below :

Q: write a c code for this code While travelling in a train, you observe some college students pulling ...

A: ALGORITHM: Declare             Integer n             Integer m Begin             Read n and m       ...

Q: Question 2.2 Write a function createPassword()with no return value to randomly select 8 capital lett...

A: NOTE: - Since the programming language is mentioned, the below problem is implemented in C language....

Q: Write a short sequence of instructions that subtracts the numbers in DI,SI and BP from the AX regist...

A: Click to see the answer

Q: Write a function that receives 3 assignment grades, a1, a2, a3, and a final grade, f, for a student ...

A: #include <iostream> #include<cmath> using namespace std; double gradeCalc(int a1, int a2...

Q: you have a memory of 128 gbs, which is divided into 16 blocks. Give the complete addresses of the fo...

A: Block size = 128 Gbs Block = 16 blocks Solution: we have size of main memory = 128 gb               ...

Q: The language is C++ 3. Write a program to calculate the factorial value of the inputnumber.Use the i...

A: The C++ program is written which will be user defined input of the function. The program uses the fo...

Q: Consider a magnetic disk with 1000 cylinders rotating at a speed of 7200 revolutions per minute. The...

A: Given:- Total number of cylinders =1000 Number of Revolutions per minute = 7200 Sector size =1024 By...

Q: Consider this code snippet.                 bnez    r1, L1              ; branch to L1 if r1 != 0   ...

A: Actually, register is a used to stores the small amount of data or information.

Q: Create the above hierarchy as follows” Create Book class having above attributes provide getter, se...

A: public class Book{        //declare data members    private String authorName;    private double cos...

Q: Question-1 There are thousands of customers in an ABC Bank who use ATM services. The ABC Bank stores...

A: The searching technique most suitable in Binary Search The given array A is sorted so the justificat...

Q: Help!

A: Click to see the answer

Q: 1) Express the following numbers in Binary Format (base 2): a) 10, b) 24, c) 1024

A: Division Quotient Remainder Number 10/2 5 0 0 5/2 2 1 1 2/2 1 0 2 1/2 0 1 3 (10)10 = ...

Q: Give the postfix expression for the tree given. (50 Puan) e a d)

A: Introduction of Postfix Expression: A tree is a non-linear data structure and there are three ways t...

Q: Using Switch statement, develop application that displays the following menu for the food items avai...

A: Since the Programming language is not mentioned in the question, we will answer this question in C++...