Click here to Skip to main content
15,888,803 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
The chase game (100 marks)
company hr has decided to conduct entertainment and fun activities for the quarter. one such activity is the chase game. in the game, there will be two teams, a chasing team and an escaping team. the game will be played in a maze of n*n slots where only one member will be present at a particular slot.
hr has divided the employees into two teams - team red (chasing team)
team blue (escaping team)
team red will try to chase and catch the team blue members. there are few conditions though for the game:
one person can catch only one person.
a person can catch the member only in the same row.
for example: a member of team red has two members of team blue in his row then he can catch only one of them. if the member was in the same column he cannot catch him.
a red team member cannot catch a member of the blue team if he is more than d units away. a member of the red team will be represented by r and a member of the blue team will be represented by b. hr wants to know the maximum number of blue team members which will be caught by red team members given the positions of members in the maze. can you help hr so they can prepare for the gifts accordingly for the winners?
example:
given below is a maze of 4*4. a member of team red cannot catch a blue team member which is more than 2 units away. a single slot is considered a single unit. row 1: both the blue team members can be caught by the red team members.
row 2: the red team member can catch two of the blue team members. but as one person can catch only one person, only one of them will be caught.
row 3: both the blue team members can be caught as both are in reach of red team members.
row 4: both the blue team members can be caught as both are in reach of red team members.
the total number of blue team members which can be caught are 7.
input format
the first line of input consists of the numbers of test cases, t.
the first line of each test case consists of two space-separated integers, n and d respectively.
next n lines each consists of n space-separated integers representing the position of red team member or blue team members represented by r and b respectively.
constraints
1<= t <=10
1<= n <=100
1<= d <=n
output format
for each test case, print the maximum number of blue team members which can be caught.
sample testcase 1
input
1
4 2
r r b b
b b b r
r b r b
r b b r
output
7


What I have tried:

I didn't get the question properly.
Posted
Updated 16-Jun-22 1:24am
v2

While we are more than willing to help those that are stuck, that doesn't mean that we are here to do it all for you! We can't do all the work, you are either getting paid for this, or it's part of your grades and it wouldn't be at all fair for us to do it all for you.

So we need you to do the work, and we will help you when you get stuck. That doesn't mean we will give you a step by step solution you can hand in!
Start by explaining where you are at the moment, and what the next step in the process is. Then tell us what you have tried to get that next step working, and what happened when you did.

If you are having problems getting started at all, then this may help: How to Write Code to Solve a Problem, A Beginner's Guide[^]

If you don't understand the question, you need to talk to your tutor about that.
 
Share this answer
 
Quote:
I didn't get the question properly.
So, in order to get better help, tell us what you get and what do you feel you're missing.
 
Share this answer
 
You describe the following sample test case 1
input:
1
4 2
r r b b
b b b r
r b r b
r b b r

output:
7

1       // t=1 test case
4 2     // n=4 dimensions; d=2 maximum distance
r r b b // 2 prisoners
b b b r // 1 prisoner
r b r b // 2 prisoners
r b b r // 2 prisoners


Before you start solve the example without coding and try to get result.

To solve the problem, as always, it must be broken down into small parts or subtasks.
Subprograms or methods are then written for the individual subtasks.

The solutions in C++ and Java will differ significantly. You'll have to choose one of the two and have to present us with at least a first draft of the programme.

Obvious subtasks would be e.g. reading in the file, creating a matrix as well as
the output of the matrix for control.

When solving, you should probably pay attention to the opponents first
with the greatest distance to take care of it so that you catch as many as possible.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900