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
A large institution, such as a bank, may have thousands of transactions to process in which no user interaction is required; whi
White raven [17]

Answer:

Mainframe Computer System

Explanation:

Mainframe systems or simply mainframes are computers used for critical application, bulk processing and transaction processing.

They are larger than the basic computers we find around. They are advantageous as they are able to process large data faster. For this reason, large institutions like banks tend to use them for processing of data because of the thousands of transactions they engage in.

They are capable of handling and processing very large amount of data quickly.

Examples of other large institutions that uses mainframe computers apart from Bank stated in the question are

1. Stock brokerage firms

2. Government agencies

3. Insurance agencies

4. Fortune 500 companies and so on.

6 0
3 years ago
Read 2 more answers
Billy used to take care of his laptop. However, one day he lost his laptop. He lost all his data, and there was no way to retrie
katrin [286]
D he didnt have backup obv

5 0
3 years ago
Read 2 more answers
Match these step-by-step directions in the order that you will find them in this course.
7nadin3 [17]

Answer:

1.Go to the View tab and select Watch.

2.Comparison

3.Editing

4.Drawing (I think)

5.Predesigned slides available for creating a new presentation

Explanation:

6 0
3 years ago
A _________ is a series of commands and instructions that you group together as a single command to accomplish a task automatica
melamori03 [73]
A macro is a series of commands and instructions that you group together as a single command to accomplish a task automatically.
8 0
3 years ago
An exclusion contract A. gives a firm the right to be the exclusive provider of a good in a particular market. B. is a form of e
irina1246 [14]

Answer:

D. All of the above

7 0
3 years ago
Other questions:
  • ​_______ consists of the analysis​ tools, technologies, and processes by which marketers dig out meaningful patterns in big data
    7·1 answer
  • What is the difference between simple and complex waveforms?
    10·1 answer
  • Importance of availability of mobile devices content that is of interest for users.
    12·1 answer
  • Explain in three to four sentences what happens to data packets once they leave a node.
    11·2 answers
  • Users at UC need to be able to quickly create a Resource record from the Project record's Chatter feed How should the App Builde
    10·1 answer
  • One condition for deadlocks is the circular-wait condition. One way to ensure that this condition never holds is to impose a tot
    12·2 answers
  • LaShawn would like to post photos in a social media app, but the program needs to be modified in order to display a greater vari
    12·2 answers
  • Jill is configuring the AutoArchive feature in Outlook 2016. What is the default setting in relation to when AutoArchive
    8·1 answer
  • How is data written to a blockchain?
    10·1 answer
  • Which layer of the OSI model provides a user interface in the form of an entry point for programs to access the network infrastr
    10·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!