0
$\begingroup$

It all about maths I don't understand, how can I solve this exercise, someone say that is a $2$-dimensional problem, but I can not figure out for myself, I already understand what to do, but I don't know why is the formula, can someone explain this exercise for a dummy? http://www.codeforces.com/contest/1/problem/A

Why the solution of this problem is $(\dfrac{m+a-1}{a}\times \dfrac{n+a-1}{a})$?

Help really appreciated.

  • 0
    @Nate Eldredge,@ Akhil Mathew I already edit2010-12-06

2 Answers 2

2

So break it into one dimensional problems. How many flagstones of length $a$ does it take to cover a path of $m$ meters? If you can trust $a$ and $m$ to be integers, $m/a$ is correct if $a$ divides $m$. Otherwise you need $\lfloor{m/a}\rfloor+1$. One way to combine these is $\lfloor(m+a-1)/a\rfloor$. Try it with some small numbers to see how it works.

For two dimensions, just multiply two one dimensional problems.

  • 0
    ok I am u$n$derst$a$nding, thanks $f$or $a$$n$swering, this problems $a$re too m$a$thematical that sometimes I try but whe$n$ I re$a$d the tutori$a$l I say WHAT?? where do they get that $f$ormula?2010-12-07
0

The answer is (the area to cover) / (the area per flagstone) + (penalty for having to use whole flagstones). Note that your answer is almost equal to (m*n)/(a*a) so it looks about right.

  • 0
    ok I was thinking is just what you said, thanks for all2010-12-07