A9474 | Magic Trick
时间限制1s
内存限制256MB
通过 / 提交0/0
题目描述
Alex enjoys performing magic tricks. He has a trick that requires a deck of $n$ cards. He has $m$ identical decks of $n$ different cards each, which have been mixed together. When Alex wishes to perform the trick, he grabs $n$ cards at random and performs the trick with those. The resulting deck looks like a normal deck, but may have duplicates of some cards.
The trick itself is performed as follows: first Alex allows you to choose a random card from the deck. You memorize the card and put it back in the deck. Then Alex shuffles the deck, and pulls out a card. If the card matches the one you memorized, the trick is successful.
You don't think Alex is a very good magician, and that he just pulls a card randomly from the deck. Determine the probability of the trick being successful if this is the case.
The trick itself is performed as follows: first Alex allows you to choose a random card from the deck. You memorize the card and put it back in the deck. Then Alex shuffles the deck, and pulls out a card. If the card matches the one you memorized, the trick is successful.
You don't think Alex is a very good magician, and that he just pulls a card randomly from the deck. Determine the probability of the trick being successful if this is the case.
输入格式
First line of the input consists of two integers $n$ and $m$ ( $1<=n,m<=1000$ ), separated by space — number of cards in each deck, and number of decks.
输出格式
On the only line of the output print one floating point number – probability of Alex successfully performing the trick. Relative or absolute error of your answer should not be higher than $10^{-6}$ .
输入输出样例
输入 #1
2 2
输出 #1
0.6666666666666666
输入 #2
4 4
输出 #2
0.4000000000000000
输入 #3
1 2
输出 #3
1.0000000000000000
In the first sample, with probability  Alex will perform the trick with two cards with the same value from two different decks. In this case the trick is guaranteed to succeed.
With the remaining  probability he took two different cards, and the probability of pulling off the trick is .
The resulting probability is 
With the remaining  probability he took two different cards, and the probability of pulling off the trick is .
The resulting probability is 
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted