Lili is practicing using her favorite character Templor Assasson. Templor Assasson has 100 base damage and 0 bonus damage at start. For each hit, bonus damage increase by 50. Lili wants to know the total damage of Templor Assasson after N hit(s).
Format input : given 1 line consist of 1 integer N the number of hit(s) of Templor Assasson.
Format output : output one number that describe the total damage of Templor Assasson.
Constraints : 1<=N<=1000000
This is the formula for calculating his attack power based on the word problem. However, the input and output provided doesn't match. 3 hits should mean his attack power is 250 rather than 450 - so you should figure out whether the sample is incorrect or the word problem.
The constraint is easy enough to do, just test whether or not "N" is bigger than 1 and less than 1000000 with an if statement or as the loop condition if you're using that.
My advice is to just start coding, even if you have no idea what to code.
125+125+200=450
This equation also equals 450, where did you get the numbers from? If you do the math a very certain way, it works, but that's not the method explained in the description of the problem, which is why I asked them to recheck.
The only way I can imagine you getting 100, 150, and then 200 is via a round-about method that wouldn't actually reflect the word problem which says clearly "For EACH hit, bonus damage increases by 50." It doesn't indicate that it's an exponential function, which also wouldn't work.
Lili wants to know the total damage of Templor Assasson after N hit(s).
First "event" - damage on that event is 100 (there were no previous hits)
Second "event" - damage on that event is 150 (i.e. 100 + 50)
Third "event" - damage on that event is 200 (i.e. 150 + 50)
TOTAL "damage" = 100 + 150 + 200.
zapshe wrote:
It doesn't indicate that it's an exponential function
You're right; it's not exponential. The final answer is a quadratic function.
I suppose that's one way of reading it - but it still makes no sense. "N" is the number of hits, meaning 3 shouldn't mean 2 hits + 1 no hit.
It doesn't imply a quadratic function either from what I've read. I was following you until you decided to add all the numbers together, I don't see how total damage could refer to that.
Even if it did refer to doing the math in this way, it, again, wouldn't make sense. For each hit, his bonus attack goes up by 50. And then it states that "N" is the number of hits. Doing what you did would mean that after 0 hits, he's at 100 damage. And that at 1 hit... he's still at 100 damage. That doesn't make sense.
Something in the problem isn't correctly stated or the sample is incorrect.
It doesn't imply a quadratic function either from what I've read.
Each term in a sum (that's what a "total" is) is 50 more than the previous. So it's an arithmetic series.
Sum of arithmetic series = (number of terms) * (average of first and last term)
where the last term is (first term) + (N-1) * (common difference)
So, here,
sum = N * ( 100 + 100 + (N-1) * 50 ) / 2
which simplifies to
N(150+50N)/2
or even
N(75+25N)
(Be careful how you code it for large N).
I can assure you that is quadratic in N.
zapshe wrote:
Doing what you did would mean that after 0 hits, he's at 100 damage. And that at 1 hit... he's still at 100 damage.
No, at 0 hits, she (apparently!) has the capacity to do "damage" of 100 when she clobbers someone, but she won't actually inflict any damage until she hits him/her/it.
You could use a loop or recursion for this. If a loop, you'll want it to run N times.
If you use recursion, you'll call the function, get 100, and then call the function N more times from within it, and return the final value. If N is 0, you'd simply return 0.
The loop may be easier to understand:
1 2 3 4 5
longint dmg = 0;
for(int i = 0; i < N; i++)
{
dmg += 100+(50*i);
}
No, @Alyssa11, you shouldn't use a loop. After all, N could be as big as a million. You've been given the sum of this particular arithmetic series. Just output the result of that formula ... one line of code ... O(1) time complexity.
no, its close but not correct.
if you want to loop to sum instead of doing it in one operation, then you want
dmg += //add to the previous total each time
what you have currently only writes the damage for the nth hit, not all n hits.
what you have, with pure =, is like this:
x = 1
x = 2
x = 3 //what is x? x is 3
when what you want is
x = 1;
x+= 2;
x+=3; //what is x? x is 6, the running total.