GreenWarfare
Member SRM 465 · 2009-12-03 · by vexorian
Problem Statement
The general has assigned you to determine how to accomplish this feat. Your main objective is to neutralize each of the enemy bases. A base is considered neutralized either if it was destroyed by a death ray or if all the energy plants supplying to it have been destroyed. There are a number of death ray canons that you can use and each canon may shoot multiple targets if necessary but can only destroy a single target with each shoot. The positions of the canons are given by two
Constraints
- baseX, baseY, canonX, canonY, plantX and plantY will each contain between 1 and 50 elements, inclusive.
- baseX and baseY will contain the same number of elements.
- canonX and canonY will contain the same number of elements.
- plantX and plantY will contain the same number of elements.
- The position given for each canon, base and energy plant will be unique.
- Each element in baseX, baseY, canonX, canonY, plantX and plantY will be between -500 and 500, inclusive.
- energySupplyRadius will be between 1 and 2000, inclusive.
- Every base will be within energySupplyRadius distance units to at least one energy plant.
{ 0 }
{ 0 }
{1,2,3}
{0,0,0}
{3}
{3}
4
Returns: 14
Use the canon to destroy each base individually, the costs are: 1, 4 and 9 gigajoules. The total cost is 14 gigajoules.
{ 0 }
{ 0 }
{1,2,3}
{0,0,0}
{2}
{2}
4
Returns: 8
In this case, the distance between the energy plant and the canon is smaller and the new optimal strategy is to destroy the energy plant with a cost of 8 gigajoules.
{3,6}
{3,6}
{1,2,3,4,5}
{5,4,2,3,1}
{1,2,5}
{1,2,5}
5
Returns: 12
Use the first canon to destroy the first two energy plants, use the second canon to destroy the remaining one.
{0}
{0}
{-10,-10,10}
{10,-10,0}
{10,10,-10}
{10,-10,0}
10
Returns: 200
Destroy the base at (10,0) and the energy plant at (-10,0), 200 gigajoules are required in total.
{0}
{0}
{3}
{3}
{1,2,3}
{0,0,0}
4
Returns: 14
Submissions are judged against all 161 archived test cases, of which 5 are shown here. Case numbers match the judge’s.
Language: C++17 · define a public class GreenWarfare with a public method int minimumEnergyCost(vector<int> canonX, vector<int> canonY, vector<int> baseX, vector<int> baseY, vector<int> plantX, vector<int> plantY, int energySupplyRadius) · 161 test cases · 2 s / 256 MB per case