spoj#FAMWEALT. Family members
Family members
Consider a family in the form of a binary tree consisting of male and female nodes. All the left nodes will be male nodes and all the right nodes will be female nodes.
Root node will be female node. The root female initially has a wealth w which she passes on down the tree. The rules are as follows :
a) all the males in the family pass half of their wealth to each of their children.
b) all the female nodes pass only half of their wealth to both their children collectively, but the male child suddenly converts it to twice the wealth received.
The members are numbered from 1 to n in the row-wise order. ie, root will be 1, it's two children will be 2 and 3 and so on.
Given wealth W of xth node, you need to find the wealth of yth node.
Input :
First line consists of t, the number of test cases(1 <= t <= 20)
Each of t lines consists of three values x, y and W (1 <= x, y <= 10^6 and 1 <= W <= 1000)
Output :
For each input test case, print the wealth of yth node in a single line (rounded off to six decimal digits)
Example :
input :
2
11 3 1
4 6 4
output:
4.000000
2.000000