Find last ant to fall off the rod

Assignment Help Basic Computer Science
Reference no: EM13486704

There are ''n'' ants on a ''n+1'' length rod. The ants are numbered from 1 to n and are initially placed at positions starting from position 1 till position n. They are moving either in left direction (denoted by ''-1'') or in the right direction (denoted by ''1''). Whenever an ant crosses the boundary of the rod it falls off the rod. You are given the initial direction of the ants. Now, whenever two ants collide their direction switches, i.e. the ant going in left direction (''-1) changes it''s direction towards right (''1'') and the ant going in the right direction (''1'') changes it''s direction towards left (''-1''). Find last ant to fall off the rod.

Note: In case two ants are falling simultaneously in the end print the index of the lower indexed ant.

Input Format:

First line contains the integer ''n'' denoting the total number of ants s.t. 1 <= n <= 1,000

Second line contains ''n'' space separated numbers (either ''1'' or ''-1'') denoting the initial directions of the ants.

Output Format:

Output a single integer which is the index (lower index in case two ants are falling simultaneously in the end) of the last ant to fall off the table.

Reference no: EM13486704

Questions Cloud

Evaluate the total mass of the neutrons in 19/9f : Calculate the total mass of the neutrons in 19/9F. Use 1.008665 amu as the mass of 1/0N(mass of a neutron). Express your answer in atomic mass units to 7 significant figures. Calculate the mass defect of 19/9F. Use 18.9984 amu as the actual mass o..
Through what potential difference did the electron move : As an electron moves through a region of space , its speed decreases from 8*10^6 m/s to 3*10^6 m/s. Through what potential difference did the electron move
What is the change in annual operating income : What is the change in annual operating income from discontinuing the talking dog product line?
What is the ratio of their angular momentum : A solid sphere and a solid disk of the same mass and radius are rolling wihtout slipping at the same speed. What is the ratio of their angular momentum
Find last ant to fall off the rod : Find last ant to fall off the rod - Output a single integer which is the index (lower index in case two ants are falling simultaneously in the end) of the last ant to fall off.
Explain weak acid and its conjugate base : A buffer contains equal amounts of a weak acid and its conjugate base and has a pH of 5.25. Which of the following values would be reasonable to expect for the pH after addition of a small amount of HCl
Find the rotational kinetic energy about its center of mass : A cylinder of mass 14.0 kg rolls without slipping on a horizontal surface. find the rotational kinetic energy about its center of mass
Determine the optimal monthly production of each wax : Clearly show the objective function and the mixing constraints for the linear program that Melnick would use to determine the optimal monthly production of each wax.
Explain a buffer contains equal amounts of a weak acid : A buffer contains equal amounts of a weak acid and its conjugate base and has a pH of 5.25. Which of the following values would be reasonable to expect for the pH after addition of a small amount of HCl. The answer: 5.15

Reviews

Write a Review

Basic Computer Science Questions & Answers

  Why deployment of ipv6 has been slow to date

Discuss some of the problems NATs create for IPsec security. (See [Phifer 2000]). Can we solve these problems by using IPv6? Why deployment of IPv6 has been slow to date. What is needed to accelerate its deployment?

  Should sgi develop any new software with derqs

Should SGI develop any new software with DERQS? If not, what tools should it acquire for new system development?

  Clash of atoms and reactions generated in brains

Do you think that Hobbes was on to something with his theory? Is there joy or fear out there, or is it all inside of us and how we perceive and react to a situation?

  You enable completeonly specific input element true or false

You can enable auto complete only for specific input element. True or False

  Features of organization to make and use information systems

Write down the features of organizations do managers require to know about to make and use information systems successfully?

  Describe the necessary hardware and software components

Your company wants to create an application that allows employees to dial in from a remote location and, using a single connection, access their voice mail, e-mail, and data files.

  Why should a company implement a csr program

3. How does the CSR program apply to today's trends and current issues in the global marketplace? 4. Whom is the company responsible to? 5. Why should a company implement a CSR program?

  Laws and regulation in telecommunications field

Do you believe we require laws and regulation in telecommunications field at all? Why or why not?

  Write a pseudocode statement

Write a pseudocode statement that subtracts the variable downPayment from the variable total and assigns the result to the variable due. Don't use integer as decimal places will be needed.

  What is a predefined control event

What is a predefined control event? Discuss its usage in programming.

  Tradeoffs involved to improve overall system performance

What are your thoughts on the tradeoffs involved when attempting to improve overall system performance. Provide examples where an increase in the performance of one resource.

  1.what is the value of the following instruction?

1.What is the value of the following instruction? mov al,01101011b shr al,22.What is the two's complement of the binary number 11010000?3.Which statement defines an array local variable consisting 40 signed words?

Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd