Class RapidDefense
java.lang.Object
topics.greedy.rapiddefense.RapidDefense
Rapid Defense Assignment
Optimizes the deployment of defender teams to invaded cities to maximize the number of victories. Demonstrates the dramatic performance difference between a Naive O(N²) greedy assignment and an Optimized O(N log N) greedy assignment via sorting.
- Author:
- vicegd
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidassignBasic(List<City> cities, List<Defender> defenders) 1.voidassignQuick(List<City> cities, List<Defender> defenders) 2.intcountVictories(List<City> cities, List<Defender> defenders) Calculates the total number of victories based on the current assignment state.
-
Constructor Details
-
RapidDefense
public RapidDefense()
-
-
Method Details
-
assignBasic
-
assignQuick
2. Optimized Greedy Assignment O(N log N)
Sorts both collections first. Uses a two-pointer approach to match the weakest winning defenders to the weakest enemies. If a defender cannot beat the weakest enemy, it is sacrificed to the strongest enemy.
-
countVictories
-