Total damage after hit

Pages: 12
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

Sample input
3
Sample output
450

Maybe u could help me with an example. Thanks.
Templor Assasson Attack Power = 100 + 50*n

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.
@zapshe,
(100)+(150)+(200)=450
The example is fine.

Arithmetic series are straightforward to sum. Use that.

Looking at the size of N you will probably need to use unsigned long long.
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.
@zapshe, RTQ

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.
Last edited on
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.
Last edited on
zapshe wrote:
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.


Now I know why I prefer CFD to computer games!



Input N: 1
100

Input N: 3
450

Input N: 1000000
25000075000000
Last edited on
That makes sense I suppose.
yep, for sample explanation is
hit 1 : 100 + 0 = 100
hit 2 : 100 + 50 = 150
hit 3 : 100 + 100 = 200
thus, total damage of templor assasson is 450.

so which syntax should I use to code?
Well, we've given you a final formula, @Alsya11. Just write some code to spit it out.

What syntax? Well, since you're here, I should code it in C++ syntax.
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
long int dmg = 0;
for(int i = 0; i < N; i++)
{
     dmg += 100+(50*i);
}
Last edited on
I give up!
aah okay, so i should use loop.. thanks guys for the discussions!
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.
Fixed a tiny mistake, should have been += rather than =

Good luck.


I give up!

I did that years ago.
I'm a 1st semester computer science college student and some programming quizzes were that hard T_T

#include<stdio.h>

int main()
{
int i,N;
scanf("%d %d", &i, &N);
long int dmg = 0;
for(int i=0,i<N,i++);
{
dmg = 100 + 50 * i ;
}
return 0;
}

i try to code, is it correct?
You aren't outputting anything. Fix that first.

Then try it for N=1000000.
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.
Last edited on
Don't loop. Simple as that!
#include<stdio.h>

int main()
{
int i,N;
scanf("%d %d", &i, &N);
long int dmg = 100;
for(int i=0,i<N,i++);
{
dmg = 100 + 50 * i ;
}
printf("%d", i);
return 0;
}

i try to run it on dev c++ but got error in 8th line T_T
can you tell me what should i fix?
Pages: 12