1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
RUDIKE [14]
3 years ago
13

You are running an art museum. There is a long hallway with k paintings on the wall. The locations of the paintings are l1, ...,

lk . These locations are real numbers, but not necessarily integers. You can place guards at locations in the hallway, and a guard can protect all paintings within 1 unit of distance from his location. The guards can be placed at any location, not just a location where there is a painting. Design a greedy algorithm to determine the minimum number of guards needed to protect all paintings.
Computers and Technology
1 answer:
Airida [17]3 years ago
3 0

Answer:

The answer to the algorithm is given below:

Explanation:

Algorithm:

#Define a set to keep track of the locations of the paintings.

location = {l1, l2, l3, l4, …, lk}

#Sort the set of locations.

Sort(location)

#Define a set to keep track of the positioned guards.

set P = {NULL}

#Define a variable to keep track of

#the location of the guard last positioned.

curr_guard = -infinity

#Define a variable to access the

#locations of the paintings.

i = 0

#Run the loop to access the

#location of the paintings.

#Since the location set has been sorted, the paintings

#are accessed in the order of their increasing locations.

while i < k:

#Check if the current painting is

#not protected by the current guard.

if location(i) > curr_guard + 1:

   

   #Assign a guard to

   #protect the painting.

   curr_guard = location(i) + 1

   

   #Add the guard to the set

   #of the positioned guards.

   P = P + {curr_guard}

#Increase the value of

#the variable i by 1.

i = i + 1

#Define a variable to count

#the number of guards placed

count = 0

#Run the loop to count

#the number of guards.

for guard in P:

count = count + 1

#Display the number of guards

#required to protect all the paintings.

print ("The minimum number of guards required are: ", count)

You might be interested in
I was just called a man in a wig ugh <br><br> Any tips for doxxing someone?
kondaur [170]

Answer:

Explanation:

hope this help

6 0
2 years ago
What is the problem, if any, with the following code?The desired output is [3,19].
vfiekz [6]

Answer: You need a temporary variable to hold the value 3

Explanation:

So, aList[0] is 3 and aList[1] is 19, if it will be as it is you litteraly say to the compiler to change aList[0] to aList[1]  at this moment aList[0] is 19 and aList[1] also is 19 and if you try to change aList[1] to aList[0]  it will not change its value because they are the same.

You need temp variable to keep one of the values.

8 0
2 years ago
A feature that displays in the lower right corner of a selected range with which you can analyze your data by using Excel tools
bagirrra123 [75]

Answer:

Quick analysis tool.

Explanation:

Excel is a spreadsheet application package found in the Microsoft office suite. it's environment on the display screen is called a worksheet and a collection of the worksheets is called a workbook. The excel packet is used for data analysis and interpretation and presentation.

When a group of cells in a worksheet is selected, a small tool kit appears that the lower right corner, it is known as a quick analysis tool. It is use for easy and fast analysis and formatting of that selected group.

5 0
3 years ago
Read 2 more answers
A network technician is asked to redesign an Ethernet network before some new monitoring software is added to each workstation o
mina [271]

Answer: network administrator

Explanation:

8 0
3 years ago
In which way is a worm different from a virius
dangina [55]
A worm as a multicell organism, but a virus is a single cell.
3 0
3 years ago
Other questions:
  • Why is it important to evaluate the website on which you plan to shop?
    11·2 answers
  • Which best describes inserting a table using the Table Gallery
    10·2 answers
  • Try writing pseudo code that describes how your device uses input data to perform the action that you want.
    9·1 answer
  • ____ are programs that need to be attached to other files to install themselves on computers without the users’ knowledge or per
    5·1 answer
  • What is the name for a hardcoded value entered into a formula ?
    8·2 answers
  • The data-linking feature that allows Internet users to skip directly from a highlighted word to a related file in another comput
    12·2 answers
  • What creative commons license allow for the work to be copied, distributed, displayed, or performed but modifications may not be
    13·1 answer
  • HELP TIMED!!!!!!!!!!!!!!!!!!!!
    5·2 answers
  • when you insert a new column, the existing columns are shifted to the ____ and the new column has the same width as the column d
    10·1 answer
  • Complete the following sentence by choosing the best answer from the options listed below.
    11·2 answers
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!