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
Arte-miy333 [17]
3 years ago
5

A terrible new disease, HORSEVID, has begun to spread among horses worldwide. Stable manager Jimmy is trying to take as many pre

cautions as possible to protect his herd from infection.
Stable manager Jimmy's barn is a long narrow building containing N stalls in a row (2≤N≤105). Some of these stalls are currently occupied by horses, and some are vacant. Having read about the importance of "social distancing", Stable manager Jimmy wants to maximize D, where D is the distance between the closest two occupied stalls. For example, if stalls 3 and 8 are the closest that are occupied, then D=5.

Two new horses recently joined Jimmy's herd and he needs to decide to which formerly-unoccupied stalls they should be assigned. Please determine how he can place his two new horses so that the resulting value of D is still as large as possible. Stable manager Jimmy cannot move any of his existing horses; he only wants to assign stalls to the new horses.

INPUT:

The first line of input contains N.

The next line contains a string of length N of 0s and 1s describing the sequence of stalls in the barn. 0s indicate empty stalls and 1s indicate occupied stalls. The string has at least two 0s, so there is at least enough room for two new horses.

OUTPUT:

Please print the largest value of D

(the closest distance between two occupied stalls) that Stable manager Jimmy can achieve after adding his two new horses in an optimal fashion.

SAMPLE INPUT:

14
10001001000010


SAMPLE OUTPUT:
2
In this example, Stable manager Jimmy could add horses to make the occupancy string look like 10x010010x0010, where x's indicate the new horses. In this case D=2. It is impossible to add the new horses to achieve any higher value of D.
Computers and Technology
1 answer:
tresset_1 [31]3 years ago
6 0

Answer:

Explanation:

Well here you only have to add 2 new horses .... so simply what you can do is find 2 slots where the gap is maximum ... lets take the given example in detail to understand the same.... here 10001001000010 here you can observe that the difference between the first two filled slots is 3 then 2 then 4 then 1....... make it a separate array ...... now as i said that we just need to place two new horses so we just need two of the biggest numbers from this array and place the new horses at the center of the corresponding slots ... like here 3 and 4 are greatest ... so one horse is placed in between the gap corresponding to 3  while other at 4 ..... after making the new array answer can be find in linear time itself... I hope this makes sense ....

Now lets understand how to program it easily so firstly after scanning all stuff ..... we will make a gap array .... then just think now what we will do is find the greatest two numbers then again putting the horses and then find our answers .... so now an easy approach is that instead of making the string again and again searching for answer .... what we do is just do half of the two greatest ones and again find the greatest one in array....

You might be interested in
Is designed to access a computer or operating system without the knowledge or permission of the user.
kramer

Answer:

Spyware

Explanation:

Spyware is a type of program that is installed with or without your permission on your personal computers to collect information about users, their computer or browsing habits tracks each and everything that you do without your knowledge and send it to remote user.

5 0
2 years ago
Which operation would occur in the equation =C3+D5*C6-B2 in excel.
UkoKoshka [18]

Answer:

The operation that will occur first is D5*C6 (multiplication).

Explanation:

Excel’s default order of operator precedence mandates that Excel perform multiplication before addition and substraction. If you want the addition or substraction to be performed before multiplication or division, they must be in parentheses.

The order of operations in exel is:

1. Evaluate items in parentheses.

2. Evaluate ranges (:).

3. Evaluate intersections (spaces).

4. Evaluate unions (,).

5. Perform negation (-).

6. Convert percentages (%).

7. Perform exponentiation (^).

8. Perform multiplication (*) and division (/), which are of equal precedence.

9. Perform addition (+) and subtraction (-), which are of equal precedence.

10. Evaluate text operators (&).

11. Perform comparisons (=, <>, <=, >=).

5 0
3 years ago
Which of the following best describes cost-benefit analysis?
d1i1m1o1n [39]

Answer:

A

Explanation:

7 0
3 years ago
What game is this? help meee
olya-2409 [2.1K]

Answer:

I am guessing animal crossing

4 0
3 years ago
Read 2 more answers
Software that interpret commands from the keyboard and mouse is known as the
goldfiish [28.3K]
The Operating system kernel, a component of all operating systems, interprets these signals by the use of a device driver, so the answer to your questions is a "driver".    <span />
3 0
3 years ago
Other questions:
  • Which game would be classified as an educational game
    14·1 answer
  • The first step in creating photographs with good backgrounds is which of the following? Learning to see the background before ta
    11·2 answers
  • What is the body of scientific knowledge based on?
    7·2 answers
  • Xml provides a standardized, non-customizable way to describe the content of a document.
    9·1 answer
  • Is frequency measured in henry.
    14·1 answer
  • While in slide show mode, if you are not careful you can close the application by clicking the x on the menu bar
    12·2 answers
  • Visual culture is an area of academic study that deals with the totality of images and visual objects produced in ____________,
    6·1 answer
  • Given two input integers for an arrowhead and arrow body, print a right-facing arrow.
    15·1 answer
  • PLEASE HELP THIS IS CONFUSING ME
    8·2 answers
  • Consider a pipelined processor with just one level of cache. assume that in the absence of memory delays, the baseline cpi of th
    13·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!