PDP-22 (2010) - Camp common - 1 (cocktails)

View as PDF

Submit solution

Points: 30 (partial)
Time limit: 1.0s
Memory limit: 64M

Author:
Problem types
Allowed languages
C, C++, Java, Pascal, Python

But you can't handle it...

A friend of yours invented an amazing cocktail consisting of N ingredients. However, they drank so much that they forgot the ratio of the ingredients in their recipe...

For N - 1 pairs of ingredients, they remember the ratio at which each pair should be added to the cocktail. Fortunately, this information is enough for your friend to recover the entire recipe.

Problem

Write a program to help your friend recover the recipe for the cocktail.

Input Files

The first line of input contains the number N. Each of the next N - 1 lines contains four numbers A, B, P, and Q, separated by spaces. This line means that the ratio of ingredient A to ingredient B in the cocktail should be P/Q.

The ingredients are numbered from 0 to N - 1.

Output Files

The output will consist of N lines.

The first line of output will contain the percentage ratio (rounded to two decimal places) of ingredient 0 in the cocktail.

Similarly, the second line of output will contain the percentage ratio of ingredient 1, and so on.

Example of INput - Output Files:

STDIN (cocktails.in)

3
0 1 9 4
2 1 1 2

STDOUT (cocktails.out)

3
60.00
26.67
13.33
1
Constraints
  • 3 \le N \le 100.
  • The numbers P and Q in the given ratios will be from 1 to 9.
  • Maximum execution time: 1 sec.
  • Maximum available memory: 64 MB.

Comments

There are no comments at the moment.