Posts Tagged ‘Series’
Two problems from the local ACM ICPC in FCIS Ain Shams
It has been a long time since I last posted here. Since this is the Eid and I have enough time to waste, it seems appropriate to add one more post. This post contains my solutions to the two problems that I wrote for the local ACM ICPC contest of FCIS Ain Shams University that was held in October 2009.
The first problem is about PQ trees. It is a simple counting problem where the input is a PQ tree, written in parenthesized form, and the output is the number of possible permutations that the tree represents. The problem statement can be accessed here. The solution is as follows. To parse the input, a simple recursive descent parser is sufficient. The number of permutations is initialized by
. For each
node
, the number of permutations
is multiplied by the factorial of the number of children of
; that is,
. And for each
node
, if
, then the number of permutations is doubled; that is,
. Otherwise, if
, then
is not affected.
The second problem is about infinite geometric series. The problem statement can be accessed here. The problem can be summarized as follows. We have an amount of data that is initially zero. Each day kilobytes are added. All the data are compressed at the end of each day by a compression ratio
, where the compression ratio is the size before compression divided by the size after compression. Note that the data are compressed multiple times. The data that are
days old are compressed
times. Given
and
, the problem asks for the the minimum storage capacity needed so that we may never run out of storage; in other words, the maximum size that our data might reach. The solution of the problem is as follows. After
days we have
chunks of data added, each was originally
kilobytes. The chunk of data that was added
days ago has been compressed
times and thus its size has been divided by
for
times. Therefore, the amount of data that we have after the
day is:
Since we seek the maximum amount of data that we will ever have, therefore we compute the amount of data after infinite number of days; that is, the amount of data as the value of tends to infinity: