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
HELP I am in the computer lab right now and I need legit reasons why i should work on a laptop instead of a computer. I dont lik
8_murik_8 [283]
Just be honest with your teacher. And say, "I'd rather work on my laptop, cause i feel uncomfortable on one of these computers." And you could say.. " I can save my work on here, so i dont lose anything if that computer messes up."
3 0
3 years ago
Read 2 more answers
Digital information is stored using a series of ones and zeros. Computers are digital machines because they can only read inform
ryzh [129]
Is known as the binary system
8 0
3 years ago
Read 2 more answers
Which value for the display property is useful when configuring horizontal navigation within an unordered list?
ikadub [295]
The Block:Inline is the value for the display property which is very useful when configuring horizontal navigation within an unordered list.The element will be still supplied as an inline element even in actual it is really a block element.
6 0
3 years ago
Cha’relle works as an editor at a publishing house. She got her position after interviewing another editor and following that ed
yuradex [85]

She used her communication skills meaning the verbal method.

Explanation:

Because she has a natural ability to talk and communicate well with others, offering them insight on any issues they may have or anything they may be lacking or struggling with. She's a natural born healer and giver.

4 0
3 years ago
Are there any tips or helpful advice for people who want to learn Photoshop?
stepan [7]

I feel like it is best to mess with it some with pictures you don't care about so you can see what would and what doesn't. that is how my sister did it and she take some grad pics. there are probably classes to

3 0
4 years ago
Other questions:
  • George borrowed some equipment from his friend for recording his monologue for his art class. He got all the equipment except th
    15·1 answer
  • Vaporization is the process in which liquid is sufficiently cooled to change states of matter from a liquid to a vapor true or f
    8·1 answer
  • How do you increase the amount of data in a sampled Google Analytics report?
    8·1 answer
  • "This part of the computer fetches instructions, carries out the operations commanded by the instructions, and produces some out
    15·1 answer
  • Whats the best app for cheaters​
    9·1 answer
  • To ease giving access to network resources for employees, you decide there must be an easier way than granting users individual
    9·1 answer
  • What are three requirements of information technology a. Accuracyb. _______________________________c. __________________________
    13·1 answer
  • A storage location in the computer's memory that can hold a piece of data is called:
    12·1 answer
  • Sami is creating a web page for her dog walking business. Which item will set the theme for her page? Background color Heading c
    9·1 answer
  • File names should be limited to 144 characters.<br><br> true or false
    12·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!