当前位置:网站首页>Deceptive Dice
Deceptive Dice
2022-08-09 23:14:00 【Here_SDUT】
Implication
Give you a dice with n sides, you can roll up to k times, you can stop rolling the dice at any time, and use the last result as your score, the probability of each side of the dice appearing is equal, let you ask forWhat is the expectation to score at most k shots.
Analysis
Let's take a 20-sided dice roll up to 3 times as an example:
Only one throw: the probability of each side is \frac{1}{20}, multiplying the score of each case, you can get: \frac{1}{20} * \sum^{20}_{i= 1}{i} = 10.5
At most two throws: The expectation of one throw is 10.5 points, so the second throw is only performed if the first score is lower than 10.5, so it is divided into one throw and two throws. The expectation of one throw is:\frac{1}{20} * \sum_{i=11}^{20}i, the expectation of two throws can be regarded as the premise that the result of the first throw is 1-10, another throw, i.e. the probability of the first throw being 1-10 times the expectation of only one throw.In summary, the formula is: \frac{1}{20} * \sum_{i=11}^{20}i+\frac{10}{20} * 10.5 = 13
Three throws at most: The expectation of throwing twice is 13, then if the result of the first throw is 1-13, then throwing twice is definitely better, so it can be divided into two situations: the result of the first throwis 14-20, then as long as you vote once, the expectation is: \frac{1}{20} * \sum_{i=14}^{20}i; the first result is 1-13, then you need to continue throwing, which can be regarded as the expectation of throwing at most two times on the basis of the first throwing result of 1-13, namely: \frac{13}{20} * 13
It can be found that each time the result is derived from the previous step, and a recursive relationship can be obtained, then to find the n
dice, roll k
times as long asIt can be pushed from 1
times to k
times. Since the interval sum is used, it can be preprocessed with the prefix sum, and the code implementation is simple.
code
#include #define LL long longusing namespace std;const int maxn = 1e5+10;const int inf = 0x3f3f3f3f;const double PI = acos(-1.0);typedef pair PII;typedef pair PLL;double s[110];LL n, k;int main() {scanf("%lld %lld", &n, &k);for (LL i = 1; i <= n; i++) {s[i] = s[i - 1] + i;}double t = s[n] / n;for (LL i = 2; i <= k; i++) {LLpos = (LL)t;t = (s[n] - s[pos]) / n + (pos)*t / n;}printf("%.8lf\n", t);return 0;}
边栏推荐
- LoRa Basics无线通信技术和应用案例详解
- [corctf 2022] 部分
- Sudoku | Backtrack-7
- Puyuan Jingdian turned losses into profits in the first half of the year, and high-end products continued to develop!Are you optimistic about "Huawei" in the instrument industry?
- TF uses constant to generate data
- 单元测试
- CVPR22 Oral|通过多尺度token聚合分流自注意力,代码已开源
- TF生成均匀分布的tensor
- LoRa无线技术在物联网应用市场的概况和发展
- 同步锁synchronized追本溯源
猜你喜欢
Sudoku | Backtrack-7
[Generic Programming] Full Detailed Explanation of Templates
6个规则去净化你的代码
FS4066耐高压1到4节内置MOS的锂电池充电管理芯片
Wps下划线怎么弄?Wps添加下划线的最全方法
Install Mysql8.0 on windos, and solve the problem of re-login exception ERROR 1045 (28000)
SQL语句及索引的优化
[corctf 2022] 部分
Pagoda measurement - building LightPicture open source map bed system
Word怎么设置图片衬于文字下方?两种方法教你设置Word图片衬于文字下方
随机推荐
基于Docker构建MySQL主从复制数据库
【云原生】4.2 DevOps 精讲篇
哪款C语言编译器(IDE)适合初学者?
ACM MM 2022 | Cloud2Sketch: Painting with clouds in the sky, AI brush strokes
LeetCode26: remove duplicates in sorted array
laravel table migration error [easy to understand]
4D Summary: 38 Knowledge Points of Distributed Systems
2022 首期线下 Workshop!面向应用开发者们的数据应用体验日来了 | TiDB Workshop Day
Technology Sharing | How to use the JSON Schema mode of interface automation testing?
论文解读(DropEdge)《DropEdge: Towards Deep Graph Convolutional Networks on Node Classification》
POWER SOURCE ETA埃塔电源维修FHG24SX-U概述
什么是源文件?
Pagoda measurement - building LightPicture open source map bed system
Cookie, session, token
【测试】语句覆盖,判定覆盖,条件覆盖,路径覆盖
Word箭头上面怎么打字
XXE-XML外部实体注入-知识点
mysql配置参数详解[通俗易懂]
AI+Medical: Using Neural Networks for Medical Image Recognition and Analysis
PHP 二维数组根据某个字段排序