A10240 | Combining Slimes
时间限制1s
内存限制256MB
通过 / 提交0/0
题目描述
Your friend recently gave you some slimes for your birthday. You have a very large amount of slimes with value $1$ and $2$ , and you decide to invent a game using these slimes.
You initialize a row with $n$ empty spaces. You also choose a number $p$ to be used in the game. Then, you will perform the following steps while the last space is empty.
1. With probability , you will choose a slime with value $1$ , and with probability , you will choose a slime with value $2$ . You place the chosen slime on the last space of the board.
2. You will push the slime to the left as far as possible. If it encounters another slime, and they have the same value $v$ , you will merge the slimes together to create a single slime with value $v+1$ . This continues on until the slime reaches the end of the board, or encounters a slime with a different value than itself.
You have played the game a few times, but have gotten bored of it. You are now wondering, what is the expected sum of all values of the slimes on the board after you finish the game.
You initialize a row with $n$ empty spaces. You also choose a number $p$ to be used in the game. Then, you will perform the following steps while the last space is empty.
1. With probability , you will choose a slime with value $1$ , and with probability , you will choose a slime with value $2$ . You place the chosen slime on the last space of the board.
2. You will push the slime to the left as far as possible. If it encounters another slime, and they have the same value $v$ , you will merge the slimes together to create a single slime with value $v+1$ . This continues on until the slime reaches the end of the board, or encounters a slime with a different value than itself.
You have played the game a few times, but have gotten bored of it. You are now wondering, what is the expected sum of all values of the slimes on the board after you finish the game.
输入格式
The first line of the input will contain two integers $n,p$ ( $1<=n<=10^{9},1<=p<10^{9}$ ).
输出格式
Print the expected sum of all slimes on the board after the game finishes. Your answer will be considered correct if its absolute or relative error does not exceed $10^{-4}$ .
Namely, let's assume that your answer is $a$ and the answer of the jury is $b$ . The checker program will consider your answer correct, if .
Namely, let's assume that your answer is $a$ and the answer of the jury is $b$ . The checker program will consider your answer correct, if .
输入输出样例
输入 #1
2 500000000
输出 #1
3.562500000000000
输入 #2
10 1
输出 #2
64.999983360007620
输入 #3
100 123456789
输出 #3
269.825611298854770
In the first sample, we have a board with two squares, and there is a $0.5$ probability of a 1 appearing and a $0.5$ probability of a 2 appearing.
Our final board states can be 1 2 with probability $0.25$ , 2 1 with probability $0.375$ , 3 2 with probability $0.1875$ , 3 1 with probability $0.1875$ . The expected value is thus $(1+2)·0.25+(2+1)·0.375+(3+2)·0.1875+(3+1)·0.1875=3.5625$ .
Our final board states can be 1 2 with probability $0.25$ , 2 1 with probability $0.375$ , 3 2 with probability $0.1875$ , 3 1 with probability $0.1875$ . The expected value is thus $(1+2)·0.25+(2+1)·0.375+(3+2)·0.1875+(3+1)·0.1875=3.5625$ .
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted