Sunday, September 7, 2014

COJ 1457. Baseball Tournament

The number of distinct pairs of N people is ( N*(N-1) )  /2 here is why
suppose we have all the members numbered from 1 to N.
1,2,3...N.
So, one can be a pair( can play a game) with 2,3,4,...N.  Total N-1 games
2 can be pair with all starting from 3 . with 3,4,5,...N. Total N-2
........
..........
and N-1 can be a pair with N. total 1 pair.
So the result is, 1+2+3+..+N-1 which has a good formula of  ( (N-1)*(N-1+1) ) /2
The final answer is the answer above multiplied with the given parameter K.


       FULL SOURCE CODE

No comments:

Post a Comment