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
|
||||||
2013-12-31 19:45:45 pushkar nagar
any tricky test cases....help wa+wa+wa+wa+wa+wa=i want to do this question anyhow... Last edit: 2013-12-31 20:18:02 |
||||||
2013-12-30 20:00:35 ήάέέϻ Ÿ
getting WA again and again.. dnt know wats going wrong :( |
||||||
2013-12-27 10:23:40 Saimadhav Heblikar
nice problem. |
||||||
2013-12-26 10:21:25 Chandan Singh
Nice problem @Pandian :) |
||||||
2013-12-26 10:01:42 Ankit Kumar
Nice problem :) |
||||||
2013-12-25 17:30:12 Deepak gupta
Enjoyed solving it :) |
||||||
2013-12-24 18:41:58 anurag garg
very very tricky question.... Last edit: 2013-12-24 18:51:58 |
||||||
2013-12-23 17:02:52 Pandian
@Ashwini : If parent is female is wealth w, both children receive only w/4 of wealth, but male child automatically doubles what it receives(only when parent is female). |
||||||
2013-12-23 05:56:17 Ashwini
@ Pandian: can you explain how much wealth both children receives respec if parent is female node with w wealth |
||||||
2013-12-23 04:12:59 Pandian
Thank you ! |