Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Problem 3 . Computer scientists have decided to play the Hunger Games, but were unhappy about the small number of players per district and the
Problem Computer scientists have decided to play the Hunger Games, but were
unhappy about the small number of players per district and the rules being too simple.
So they came up with a new version of the game, and asked you to come up with an
efficient data structure to handle the Games.
Rules: There are n districts, numbered to n Each district has its own number of
players: initially, each district has m players. Each player has a score nonnegative
integer initially set to Each district also has an integer score, initially set to
When two districts play against each other, their best players compete one from
each district The winning player and their district both have their score incremented; the losing player and their district both have their score decremented.
When a player reaches score they are disqualified removed from their district
and the game
When a district reaches players, it is disqualified removed from the game
The last district in play wins.
Your task: Your data structure should use Onm space, and implement the following
operations:
getKthDistrictk: Given a positive integer k return a pointer to the district
currently ranked k
th ie the district with the highest score is ranked first or
null if k n Ties are broken by district number, so if district and district
have the same score, district is considered better because This
operation should run in Olog n time.
competek j kwins: Given two positive integers k j n and a Boolean
kwins, record the result of a game between the districts currently ranked k
th
and j
th and update the data structure according to the rules or do nothing if
k j or if either k or j is not between and n If kwins is True, then the
k
th district wins; otherwise, the j
th district wins. This operation should run in
Olog n log m time.
getStrongest: Returns a pointer to the district whose best player has the
largest score. This operation should run in On time.
If I were to implement a min heap to store the district in order of rank, and stores the value of their total points, and each node in the min heap points to a max heap that contains the districts m players, would it satisfy the above conditions?
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started