Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Help me with pythonBessie is a robovine, also known as a cowborg. She is on a number line trying to shoot a series of )

Help me with pythonBessie is a robovine, also known as a cowborg. She is on a number line trying to shoot a series of )T(105 targets located at distinct positions. Bessie starts at position 0 and follows a string of )C(105 commands, each one of L,F, or R :
L: Bessie moves one unit to the left.
R: Bessie moves one unit to the right
F: Bessie fires. If there is a target at Bessie's current position, it is hit and destroyed, and cannot be hit again.
If you are allowed to change up to one command in the string to a different command before Bessie starts following it, what is the maximum number of targets that Bessie can hit?
INPUT FORMAT (pipe stdin):
The first line contains T and C.
The next line contains the locations of the T targets, distinct integers in the range -C,C.
The next line contains the command string of length C, containing only the characters F,L, and R.
OUTPUT FORMAT (pipe stdout):
Print the maximum number of targets that Bessie can hit after changing up to one command in the string.
SAMPLE INPUT:
37
0-11
LFFRFRR
SAMPLE OUTPUT:
3
If you make no changes to the string, Bessie will hit two targets:
\table[[Command,Position,Total Targets Hit],[Start,0,0],[L,-1,0],[F,-1,1],[F,-1,1],[R,0,1],[F,0,2],[R,1,2],[R,2,2]]
If you change the last command from R to F, Bessie will hit all three targets:
\table[[Command,Position,Total Targets Hit],[Start,0,0],[L,-1,0],[F,-1,1],[F,-1,1],[R,0,1],[F,0,2]]
R
F
12
SAMPLE INPUT:
15
0
FFFFF
SAMPLE OUTPUT:
1
If the commands are left unchanged, the only target at 0 will be destroyed. Since a target cannot be destroyed multiple times, the answer is 1.
SAMPLE INPUT:
56
12345
FFRFRF
SAMPLE OUTPUT:
3
SCORING:
Inputs 4-6: T,C1000
Inputs 7-15: No additional constraints.
Problem credits: Suhas Nagar
image text in transcribed

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

Concepts Of Database Management

Authors: Philip J. Pratt, Joseph J. Adamski

4th Edition

ISBN: 0619064625, 978-0619064624

More Books

Students also viewed these Databases questions