Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Please answer this in PYTHON. Raging Rhinos (mBIT ) ( Input is taken during run time and output printed on the console) Fully grown rhinos

Please answer this in PYTHON.

Raging Rhinos (mBIT ) ( Input is taken during run time and output printed on the console) Fully grown rhinos can weigh over 5000 pounds! The rhinos are in a fit of rage, and they are ready to duke it out in an all-out frenzy. The rules are as follows: the rhinos all stand in a line facing either to the left or right. All rhinos begin with a positive amount of stamina. At the sound of the bell, all rhinos will begin charging in their respective directions at the same speed, and upon encountering another rhino, they will collide. The rhino with less stamina is knocked out of the line while the rhino with more stamina continues in the same direction, with its stamina reduced by the stamina of its opponent. If two rhinos with the same stamina collide, both drop out of the line. Can you determine the state of the rhinos after all collisions? Note that a rhino never changes directions. Input Format: The first line contains N, the number of rhinos (1 N 105).

Among the next N lines, the ith line describes the ith rhino from the left. Each line contains two integers si and di denoting the initial stamina and direction of each rhino (1 si 109). If di = 0, then the rhino is facing left, otherwise if di = 1, it is facing

right. Output Format: Print one line containing M, the number of rhinos still running in on the line. On the next M lines, print two space-separated integers containing the remaining stamina and direction of each rhino. Describe the rhinos in the order they appear on the line (from left to right). Sample Input 1: 4 39 1 20 0 21 0 12 0 Sample Output 1: 2 2 0 12 0 The first and second rhino collide, and the first rhino is victorious with 19 remaining stamina. Then the first and third rhino collide, and the third rhino is victorious with 2 remaining stamina. The third and fourth rhino never touch because they are moving in the same direction.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Graph Database Modeling With Neo4j

Authors: Ajit Singh

2nd Edition

B0BDWT2XLR, 979-8351798783

Students also viewed these Databases questions