| ||You are developing a computer game where attack towers protect a city from approaching enemies. You need to calculate the damage that can be done to the enemy by a certain configuration of towers.
The towers are modeled as points on the X-Y plane. You are given ints towersX and towersY, where (towersX[i], towersY[i]) are the coordinates of the i-th tower. Each tower has an initial energy of damage and an effective radius of r.
When the enemy approaches, the towers attack as follows:
First, the towers can redistribute their energy. If the distance between two towers is less than or equal to r, one of them can transmit any amount of its energy to the other. When energy is transmitted between towers, half of it is lost. (So, if tower 1 transmits 10 energy to tower 2, tower 1 will lose 10 energy and tower 2 will receive only 5 energy.)
Then, the towers will attack. If the distance between the enemy and a tower is less than or equal to r, that tower can attack the enemy. When a tower attacks, all of its energy becomes damage to the enemy.
You are given the coordinates of the enemy as (enemyX, enemyY). Return the maximal total damage that can be done to the enemy.
|Parameters:||int, int, int, int, int, int|
|Method signature:||double maxDamage(int towersX, int towersY, int r, int damage, int enemyX, int enemyY)|
|(be sure your method is public)|
|-||The amount of energy a tower can accumulate is unlimited.|
|-||The returned value must have an absolute or relative error less than 1e-9.|
|-||towersX will contain between 1 and 50 elements, inclusive.|
|-||towersY will contain the same number of elements as towersX.|
|-||Each element of towersX will be between 0 and 1000, inclusive.|
|-||Each element of towersY will be between 0 and 1000, inclusive.|
|-||All the towers' positions will be distinct.|
|-||r will be between 1 and 500, inclusive.|
|-||damage will be between 1 and 100, inclusive.|
|-||enemyX will be between 0 and 1000, inclusive.|
|-||enemyY will be between 0 and 1000, inclusive.|
|-||The enemy's position will be distinct from all the towers' positions.|
|Tower 3 transmits 10 energy to tower 2 (tower 2 receives 5 energy).|
Then tower 2 transmits 15 energy to tower 1 (tower 1 receives 7.5 energy).
Then tower 1 transmits 17.5 energy to tower 0 (tower 0 receives 8.75 energy).
Finally, tower 0 attacks the enemy, and its 18.75 energy becomes damage.