A neighborhood of Park Street is raided by soldiers in search of Agent Y. They land on different buildings on a helicopter. The rooftops of these buildings are connected to each other through ladders. Each soldier can take control of the buildings in a straight line (left-right and forward-backward), with respect to the building/position they have been dropped at. They cannot take control of buildings diagonally. There are 8 buildings in each row and column. Your goal is to determine and return the total number of buildings that are controlled by these group of soldiers. Note: A soldier also controls the building on which he/she is currently positioned/ dropped. Input Specification: input1: An integer value representing the number of soldiers that have landed input2: A 2-D array of size input1*2 representing 'x' and 'y' coordinate positions of the soldiers starting from {1,1} Output Specification: Return the total number of buildings that are controlled by the soldiers.

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question

 

 

A neighborhood of Park Street is raided by soldiers in search of Agent Y. They
land on different buildings on a helicopter. The rooftops of these buildings are
connected to each other through ladders. Each soldier can take control of the
buildings in a straight line (left-right and forward-backward), with respect to the
building/position they have been dropped at. They cannot take control of
buildings diagonally.
There are 8 buildings in each row and column. Your goal is to determine and
return the total number of buildings that are controlled by these group of
soldiers.
Note: A soldier also controls the building on which he/she is currently positioned/dropped.
Input Specification:
input1: An integer value representing the number of soldiers that have
landed
input2: A 2-D array of size input1*2 representing 'x' and 'y' coordinate
positions of the soldiers starting from {1,1}
Output Specification:
Return the total number of buildings that are controlled by the soldiers
Example 1:
input1: 2
input2: {{ 5.5).(5.3}}
Transcribed Image Text:A neighborhood of Park Street is raided by soldiers in search of Agent Y. They land on different buildings on a helicopter. The rooftops of these buildings are connected to each other through ladders. Each soldier can take control of the buildings in a straight line (left-right and forward-backward), with respect to the building/position they have been dropped at. They cannot take control of buildings diagonally. There are 8 buildings in each row and column. Your goal is to determine and return the total number of buildings that are controlled by these group of soldiers. Note: A soldier also controls the building on which he/she is currently positioned/dropped. Input Specification: input1: An integer value representing the number of soldiers that have landed input2: A 2-D array of size input1*2 representing 'x' and 'y' coordinate positions of the soldiers starting from {1,1} Output Specification: Return the total number of buildings that are controlled by the soldiers Example 1: input1: 2 input2: {{ 5.5).(5.3}}
Output: 22
Explanation:
When two soldiers are dropped at positions (5,5) and (5,3) then the total
number of buildings controlled by soldiers are 22.
No. of buildings in column 3 + No. of buildings in column 5 + No. of buildings in
row 5-No. of buildings common among them = 8+8+8 -2=22
Therefore, 22 is returned as the output.
Example 2:
input1: 1
input2: {{4,4}}
Output: 15
Explanation:
When one soldier is dropped at position (4,4) then the total number of buildings
controlled by the soldier is 15.
No. of buildings in column 4 + No. of buildings in row 4 - No. of buildings common
among them = 8+8-1=15
Therefore, 15 is returned as the output.
Transcribed Image Text:Output: 22 Explanation: When two soldiers are dropped at positions (5,5) and (5,3) then the total number of buildings controlled by soldiers are 22. No. of buildings in column 3 + No. of buildings in column 5 + No. of buildings in row 5-No. of buildings common among them = 8+8+8 -2=22 Therefore, 22 is returned as the output. Example 2: input1: 1 input2: {{4,4}} Output: 15 Explanation: When one soldier is dropped at position (4,4) then the total number of buildings controlled by the soldier is 15. No. of buildings in column 4 + No. of buildings in row 4 - No. of buildings common among them = 8+8-1=15 Therefore, 15 is returned as the output.
Expert Solution
steps

Step by step

Solved in 2 steps with 3 images

Blurred answer
Knowledge Booster
Order Statistics
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education