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]
2 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]2 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
Please help
MA_775_DIABLO [31]

Answer:

Key name

How to use it

Shift

Press Shift in combination with a letter to type an uppercase letter. Press Shift in combination with another key to type the symbol shown on the upper part of that key.

Caps Lock

Press Caps Lock once to type all letters as uppercase. Press Caps Lock again to turn this function off. Your keyboard might have a light indicating whether Caps Lock is on.

Tab

Press Tab to move the cursor several spaces forward. You can also press Tab to move to the next text box on a form.

Enter

Press Enter to move the cursor to the beginning of the next line. In a dialog box, press Enter to select the highlighted button.

Spacebar

Press the Spacebar to move the cursor one space forward.

Backspace

Press Backspace to delete the character before the cursor, or the selected text.

Typing (alphanumeric) keys. These keys include the same letter, number, punctuation, and symbol keys found on a traditional typewriter.

Control keys. These keys are used alone or in combination with other keys to perform certain actions. The most frequently used control keys are Ctrl, Alt, the Windows logo key  Picture of the Windows logo key, and Esc.

Function keys. The function keys are used to perform specific tasks. They are labeled as F1, F2, F3, and so on, up to F12. The functionality of these keys differs from program to program.

Navigation keys. These keys are used for moving around in documents or webpages and editing text. They include the arrow keys, Home, End, Page Up, Page Down, Delete, and Insert.

Numeric keypad. The numeric keypad is handy for entering numbers quickly. The keys are grouped together in a block like a conventional calculator or adding machine.

The following illustration shows how these keys are arranged on a typical keyboard. Your keyboard layout might be different.

Explanation:

3 0
1 year ago
Which form of media allows the audience to share in and comment on the content immediatly
Luba_88 [7]

twitter

they will allow you to share comments about any topic you want

4 0
3 years ago
In the code below, what's the final value of the variable x?
Lana71 [14]

Answer:

First equation x=4

second equation x=3

Explanation:

The question is telling us that 'X' is equal to 8. It's another way of representing this number using X as the variable replacing it.

We input 8 instead of the X to solve the equation, and here in the picture, you can see where I went from there.

Do the same thing for the other equation.

I hope this helps :)

3 0
2 years ago
Which of the following data types can hold a fractional (decimal) number?
zvonat [6]
A float data type can hold a decimal number.
6 0
2 years ago
You want to save 20 of your vacation pictures on your computer. Which is the best place to save them?
hodyreva [135]
I would say probably to a hard drive or to your downloads
4 0
3 years ago
Read 2 more answers
Other questions:
  • Mm
    10·1 answer
  • Within the hardware of the personal computer temporary memory is known as
    10·2 answers
  • Which of the following commands contains an error?
    8·1 answer
  • Free 100 point to first to answer
    5·2 answers
  • Which two options are negotiated via ncp during the establishment of a ppp connection that will use the ipv4 network layer proto
    7·1 answer
  • A Raycast returns a float that tells you how far away an Object is
    8·1 answer
  • When a person or organization uses the services of another professional, that person or organization is called the _______
    15·1 answer
  • How many ways do advertisers determine target audiences ??????
    15·1 answer
  • List any three importance of computer points​
    8·1 answer
  • Which of the following best describes a balanced reaction
    11·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!