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
Which of the following questions will most likely be answered by displaying data on a line graph?
Artemon [7]
I'm pretty sure the answer is b
4 0
3 years ago
>What is the output of the following code:
ozzi

Answer:

Given code output is "786".

Explanation:

Code:

list1 = [ 'cyber', 786 , 2.23, 'square', 70.2 ]#defining a list list1 that holds value in parameter

print (list1[1] )#use a print method that prints list index value

In the given code a list "list1" is declared that holds value in it and in the next step a print method is declared that prints the first index value of the list.

5 0
2 years ago
Which of the following tools might the security administrator use to perform further security assessment of this issue?
Y_Kistochka [10]

Answer:

A.Port scanner

Explanation:

thats correct answer★

4 0
2 years ago
Which of the following method calls are legal?a. mathMethod(x);b. mathMethod(y);c. mathMethod(x, y);d. mathMethod(x + y);e. math
Roman55 [17]

Answer:

Option a, b, d, f, and j is legal method calls.

Explanation:

In the given question some information is missing, that is the method definition which can be described as follows:

Method definition:

int x =2, y=3; //defining integer variable

int mathMethod (int x)  //method definition

{//method body

int z=x+y; //calculate value

return z;  //return value

}

In the given question option a, b, d, f, and j  is legal, because these options follow the correct syntax, and other option were incorrect which can be defined as follows:

  • In option c, It is illegal because it accepts only one parameter.
  • In option e, It is accepts long number, that's why it is illegal.
  • In option g, It accepts float value, that's why it is illegal.
  • In option h, It doesn't accepts any parameter.
  • In option i, It isn't use in method.
7 0
3 years ago
13 POINTS! Which option is used to ensure the integrity and authenticity of a Word document but requires additional services to
Ksju [112]

A. digital encryption

5 0
3 years ago
Read 2 more answers
Other questions:
  • Consider the provided C++ code in the main.cpp file: The function func2 has three parameters of type int, int, and double, say a
    8·1 answer
  • What is the windows server 2012 r2 feature that enables you to maintain previous versions of files on a server, so that if users
    10·1 answer
  • Your company received a call from a historical society inquiring about the possibility of networking a two-century-old building
    15·1 answer
  • Why do most laptops have LCD rather than OLED displays, which are found on mobile devices?
    14·1 answer
  • g Design a Boolean function called isPrime, that accepts an integer as an argument and returns True if the argument is a prime n
    14·1 answer
  • Universal Containers is building an integration between Salesforce and their Accounting system. The integration will utilize out
    8·1 answer
  • Can Someone help plz?
    11·1 answer
  • Ashton assigned a string value to a variable. Which program statement should he use?
    5·1 answer
  • What are the pros and cons of being a single decision maker
    8·1 answer
  • You were just hired as an IT Specialist for Smalltown School District. Your first assignment is to review a problem area& in
    11·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!