Submit | All submissions | Best solutions | Back to list |
FAMWEALT - 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:
- all the males in the family pass half of their wealth to each of their children.
- 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. i.e., root will be 1, the 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 integer values x, y and W (1 ≤ x, y ≤ 106 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
Added by: | Pandian |
Date: | 2013-12-19 |
Time limit: | 1s |
Source limit: | 50000B |
Memory limit: | 1536MB |
Cluster: | Cube (Intel G860) |
Languages: | All |
hide comments
|
||||||
2016-08-19 17:32:50
nice problem indeed ! XD |
||||||
2016-07-18 21:29:49
xDDD |
||||||
2016-06-13 15:08:14 Siddharth Singh
Nice Problem :) |
||||||
2016-01-20 02:30:43
I was first thinking about finding the lowest common ancestor, but then a better idea came to my mind .. AC in one go .. NIce and simple .. :) |
||||||
2015-10-01 01:08:56 PRINCE KUMAR
my 50TH... |
||||||
2015-06-27 09:08:23 Insomniac
AC in one go!!.........My 50th :) |
||||||
2015-05-23 18:50:05 :.Mohib.:
Awsm que!! Just love to solve this type of que... Keep sharing que like this... :) |
||||||
2014-08-18 06:08:48 Prakhar Gupta
i have a doubt...does the male passes half of its money to both children...that leaves him with zero money, then how come in second test case the male child still have money?? |
||||||
2014-06-20 12:55:29 kelaseek
float and int is enough for o(logx+logy) |
||||||
2014-04-23 15:18:20 AlcatraZ
read question CAREFULLY..costed many WA.. rest is just pen and paper.. Nice problem.. |