Question: use cuda c + + language, please give the working code not what i have to do 1 Problem Statement There is a battlefield which
use cuda c language, please give the working code not what i have to do
Problem Statement
There is a battlefield which can be represented as a grid of size
There are no of tanks placed randomly on the grid with ids to
at integer coordinates Consider the tanks to be point sized objects.
Your task is to simulate a game between tanks with following rules and re
turn the score of each tank at the end of the game.
The rules are as follows:
Each tank has Health Points HP allotted to them given in an array. A
tank is considered destroyed at the end of a round if its HP dropped to
The game consists of multiple rounds, in each round the tanks which are
not yet destroyed in the previous rounds fire in the direction of other
tanks.
In kth round the Tank i will fire in the direction of Tank ikT Since
a tank cannot fire at its own direction you can consider every round which
is a multiple of to be a null round ie the tanks do not fire at each other.
Each hit taken by a tank reduces its HP by and increase the score of
the tank which fired that shot by
The way hit detection works is that if in a round Tank i fires in the
direction of Tank the shot will hit the first tank it encounters in that
direction which is not yet destroyed. So depending on the layout of the
grid there can be following scenarios and their logical variations:
The simplest case in which there are no tanks between Tanks i and j
and Tank is not destroyed, so the shot hits Tank jTank i fires at Tank and hits Tank
There was a tank Tank between Tank i and j which was not yet
destroyed in which case the shot will hit Tank Tank i fires at Tank and hits Tank
There were Tanks and between Tanks i and in that order, Tank k
was destroyed in some previous round but Tank is not yet destroyed
in which case the shot hits Tank
There are Tanks i j & k in the ij direction and Tank j was destroyed in some previous round but Tank is still not destroyed in which case the shot will hit Tank k Tank i fires at Tank and hits Tank
The game finishes when there is only one or no tanks left ie not destroyed
on the battlefield.
A tank is considered destroyed only at the end of round in which its HP
drops to it will still fire its shot in that round and it will still take
hits from all the shots which encounter it in that round and the scores of
each of the tanks which fired those shots will increase by
Hint: A line can be represented using equation c ie every unique
combination of & c represents a unique line. If you are taking this approach
try to think of how you can avoid the use of in the equation.All the Tanks in the ij direction except Tank i were destroyed in previous rounds in which case the shot will not hit any tank.
Input and Output Format
Input Format
The first line contains integers M N T H where, & are grid sizes,
is the no of tanks on the battlefield and is the starting health points
of each tank all tanks have same starting HP
T lines follow with each line containing Tank coordinates, specifically line
i contains integers representing & y coordinates respectively of Tank
i
Output Format
The final score of each Tank should be updated on the 'score' array in the host
which will get written to output file such that Line i represents final score of
Tank i
Constraints
two tanks lie the same point the grid.
Sample Input
Sample Output
two tanks lie the same point the grid.
Sample Input
Sample Output
input testcase:
output testcase:
the explanation of the problem is given in the image :
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
