Question

In: Computer Science

Jojo the wizard is currently on a dragon’s lair. To escape from the lair, Jojo needs...

Jojo the wizard is currently on a dragon’s lair. To escape from the lair, Jojo needs to defeat the elder dragon. Jojo is currently a wizard under training, so he knows only one spell : the fireball spell. The dragon’s body can be represented as an array of size N , where each part of the dragon’s body, from its head to its tail, is numbered with integer from 1 to N. Each body part has its sensitivity to fire a i . If a i is positive, then the fireball spell will deal a i damage to the dragon. If a i is negative, it will heal the dragon by − a i health points instead. The fireball spell is a spell which deals damage to the dragon’s body on exactly K consecutive body parts. That is, if Jojo casts the spell on i-th body part, then the fireball will attack the parts [i, i+1, i+2, ..., i + K −1]. For example, if the dragon’s body is [1 , 2 , − 2 , 4 , 5], and K is 3, then Jojo may cast the spell on 1st, 2nd, and 3rd body part, which deals 1, 4, and 7 damage respectively. Jojo can’t cast the spell on 4 or 5 since the fireball must hit exactly K body parts of the dragon. As Jojo can only cast the spell one time, Help Jojo determine the maximum damage output he can deal to the dragon.

Solutions

Expert Solution

Step 1: Start

Step 2: Create a variable N to store size of the Dragon and get its value

Step 3: Create an integer array A to store the Dragon's body and get the values for each element

Step 4: Create a variable K to store size of the spell and get its value.

Step 5: Create a new integer variable x=0

Step 6: Create two integer variable i=x+0 and sum_of_damage=0

Step 7: Add the value in ith element in array to sum_of_damage i.e sum_of_damage=sum_of_damage + A[i+x]

Step 8: Repeat Step 6 and Step 7 for different values of i=x+1 to i=x+k-1

Step 9: Increment the value of x by 1 i.e x=x+1

Step 10: Create a variable max to store the maximum damage value and store the value of sum_of_damage in it i.e max=sum_of_damage

Step 10: If x+k<n, Repeat Step 5 to Step 9 to calculate the value for sum_of_damage. If sum_of_damage>max assign the value of sum_of_damge to max i.e max=sum_of_damage

Step 11: Return the value of max

Step 12: Stop


Related Solutions

Jojo the wizard is currently on a dragon’s lair. To escape from the lair, Jojo needs...
Jojo the wizard is currently on a dragon’s lair. To escape from the lair, Jojo needs to defeat the elder dragon. Jojo is currently a wizard under training, so he knows only one spell : the fireball spell. The dragon’s body can be represented as an array of size N , where each part of the dragon’s body, from its head to its tail, is numbered with integer from 1 to N. Each body part has its sensitivity to fire...
BROKEN SPEEDOMETER The cycling competition is near, so jojo needs to practice cycling. he used a...
BROKEN SPEEDOMETER The cycling competition is near, so jojo needs to practice cycling. he used a speedometer found in his basement to measure his speed. however, it turns out that the speedometer is not usual! the digits on the speedometer can only count up to 2. if we add a value to a digit 2, it will revert to 0 and adds a value to the next digit. for example, the numbers [0,1,2,3,4,5,6,7] will be shown as [0,1,2,10,11,12,20,21] on the...
Cambridge Ltd is currently suffering from a depression in the market for its products and needs...
Cambridge Ltd is currently suffering from a depression in the market for its products and needs to decide which of three products it should continue produce, so that it can maximise its profits. They have recently employed the services of Research It Ltd who have researched Cambridge Ltd and their products and have produced the following information: Research It Ltd. have provided information for three levels of demand, low, medium and high and a probabilities for each level of demand...
Stairs Jumping One day, Jojo takes a vacation to the mountains to get away from the...
Stairs Jumping One day, Jojo takes a vacation to the mountains to get away from the cities. While climbing the mountain, Jojo came to an area filled with thousands of stairs to get to the top. However, there was a rule in the mountain which stated that Jojo had to jump over the stairs with same height to get to the top of the mountain. Listening to these rules, Jojo wanted to know what is the minimum required height he...
Wizard Inc. has to choose between two mutually exclusive projects. If it chooses project A, Wizard...
Wizard Inc. has to choose between two mutually exclusive projects. If it chooses project A, Wizard Inc. will have the opportunity to make a similar investment in three years. However, if it chooses project B, it will not have the opportunity to make a second investment. The following table lists the cash flows for these projects. If the firm uses the replacement chain (common life) approach, what will be the difference between the net present value (NPV) of project A...
Wizard Inc. has to choose between two mutually exclusive projects. If it chooses project A, Wizard...
Wizard Inc. has to choose between two mutually exclusive projects. If it chooses project A, Wizard Inc. will have the opportunity to make a similar investment in three years. However, if it chooses project B, it will not have the opportunity to make a second investment. The following table lists the cash flows for these projects. If the firm uses the replacement chain (common life) approach, what will be the difference between the net present value (NPV) of project A...
What is the value of escape velocity for a body to escape from.earth gravitational field
Explain escape velocity details. What is the value of escape velocity for a body to escape from earth gravitational field 
In an attempt to escape from a deserted island, a castaway builds a raft and sets...
In an attempt to escape from a deserted island, a castaway builds a raft and sets sail for the sea. The wind changes a lot during the day and flies along the following straight lines: 2.60 km and 45.0 ° north of west, then 4.80 km and 60.0 ° south of east, then 1.60 km and 5.00 ° east of north, and finally 2.70 km and 13.0 ° north of the east. Use the analytical method to find the resulting...
Calculate the amount of energy required to escape from the surface of the following bodies, relative...
Calculate the amount of energy required to escape from the surface of the following bodies, relative to that required to escape from the surface of Earth. (a)    Uranus                      energy to escape Earth (b)    Mars                              energy to escape Earth
Roads A, B, and C are the only way to escape from a certain provincial prison....
Roads A, B, and C are the only way to escape from a certain provincial prison. Prison records show that, of the prisoners who tried to escape, 9 % used road A, 14 % used road B, the remainder used road C. The records also indicate that 85 % of those who tried to escape using road A were captured. 13 % of those using road B were captured, and 58 % of those using road C were captured. Use...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT