Monday, August 25, 2014

COJ 1273. Domino Factory

The most important thing is to correctly calculate the number of domino figures. So how do we do it?
Suppose we have numbers from 0 to N, how many distinct pairs we can make?
0-1,0-2.0-3.......,0-N
which gives N+1 pairs
so now let's consider all the new dominoes with 1
1-1,1-2,1-3,...1-N
total of N pairs
than for 2 it is
2-2,2-3,2-4,....2-N
N-1 pairs
and so on until the last one which is 0 .
So the total number of pairs of number from 0 to N is the sum of numbers from 1 to N+1 which has a good formula ( (N+1)*(N+2) )/2. The answer will be the sum of number from 1 to N+1 multiplied with the 2 sides of domino.


       FULL SOURCE CODE

No comments:

Post a Comment