prompt asking, to be programmed in Java?

Computer Networking: A Top-Down Approach (7th Edition)
7th Edition
ISBN:9780133594140
Author:James Kurose, Keith Ross
Publisher:James Kurose, Keith Ross
Chapter1: Computer Networks And The Internet
Section: Chapter Questions
Problem R1RQ: What is the difference between a host and an end system? List several different types of end...
icon
Related questions
Question

What is the given prompt asking, to be programmed in Java?

You are creating a game where the hero, called Hercules, has to fight n angry
and magical birds with multiple heads. The ith bird has birds[i] total number of
heads.
Assume it takes your hero 1 second to behead all heads of a specific bird, but
after that magically this bird gets back half of its heads. If the bird had initially b
heads, then after it is beheaded it grows floor(b/2) heads back.
You have m seconds to cut as many heads as possible from the birds.
a) Describe an efficient algorithm that finds the maximum number of heads cut
by Hercules. Hint: start with the bird that has the maximum number of heads,
etc.
b) Write a java class that implements your algorithms (copy paste
implementation).
c) What is the data structure you used? Hint: Some options arrays, sorted
arrays, linked lists, heaps etc. Choose the best.
d) What is the running time of your algorithm?
//given an array @birds of size n, and @m the available seconds return the
//maximum number of head cut by the hero
int maxStymphBirds(int[] birds, int m)
Output
A single integer, the maximum number of heads you can cut in m seconds.
Example 1
n = 3
m = 3
birds = [20, 1, 15]
output = 45
The 1st second, cut 20 heads of the 1st bird, and it gets floor(20/2) = 10 heads
back.
The 2nd second, cut 15 heads of the 3rd bird, and it gets floor(15/2) = 7 heads
back.
The 3rd second, cuts 10 heads of the 1st bird again, and it gets floor(10/2) = 5.
In total 20 + 15 + 10 = 45 heads cut.
Transcribed Image Text:You are creating a game where the hero, called Hercules, has to fight n angry and magical birds with multiple heads. The ith bird has birds[i] total number of heads. Assume it takes your hero 1 second to behead all heads of a specific bird, but after that magically this bird gets back half of its heads. If the bird had initially b heads, then after it is beheaded it grows floor(b/2) heads back. You have m seconds to cut as many heads as possible from the birds. a) Describe an efficient algorithm that finds the maximum number of heads cut by Hercules. Hint: start with the bird that has the maximum number of heads, etc. b) Write a java class that implements your algorithms (copy paste implementation). c) What is the data structure you used? Hint: Some options arrays, sorted arrays, linked lists, heaps etc. Choose the best. d) What is the running time of your algorithm? //given an array @birds of size n, and @m the available seconds return the //maximum number of head cut by the hero int maxStymphBirds(int[] birds, int m) Output A single integer, the maximum number of heads you can cut in m seconds. Example 1 n = 3 m = 3 birds = [20, 1, 15] output = 45 The 1st second, cut 20 heads of the 1st bird, and it gets floor(20/2) = 10 heads back. The 2nd second, cut 15 heads of the 3rd bird, and it gets floor(15/2) = 7 heads back. The 3rd second, cuts 10 heads of the 1st bird again, and it gets floor(10/2) = 5. In total 20 + 15 + 10 = 45 heads cut.
Expert Solution
steps

Step by step

Solved in 2 steps with 4 images

Blurred answer
Recommended textbooks for you
Computer Networking: A Top-Down Approach (7th Edi…
Computer Networking: A Top-Down Approach (7th Edi…
Computer Engineering
ISBN:
9780133594140
Author:
James Kurose, Keith Ross
Publisher:
PEARSON
Computer Organization and Design MIPS Edition, Fi…
Computer Organization and Design MIPS Edition, Fi…
Computer Engineering
ISBN:
9780124077263
Author:
David A. Patterson, John L. Hennessy
Publisher:
Elsevier Science
Network+ Guide to Networks (MindTap Course List)
Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:
9781337569330
Author:
Jill West, Tamara Dean, Jean Andrews
Publisher:
Cengage Learning
Concepts of Database Management
Concepts of Database Management
Computer Engineering
ISBN:
9781337093422
Author:
Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:
Cengage Learning
Prelude to Programming
Prelude to Programming
Computer Engineering
ISBN:
9780133750423
Author:
VENIT, Stewart
Publisher:
Pearson Education
Sc Business Data Communications and Networking, T…
Sc Business Data Communications and Networking, T…
Computer Engineering
ISBN:
9781119368830
Author:
FITZGERALD
Publisher:
WILEY