CF 441E Valera and Number

CF 441E

Description

一共执行\(k\)次,每次有\(p\%\)把\(x * 2\),有\((100 - p)\%\)把\(x + 1\)。问二进制下\(x\)末尾期望\(0\)的个数。

Solution

设\(f[i][j]\)为执行第\(i\)次后\(x + j\)末尾期望\(0\)的个数

加一:$f[i + 1][j - 1] = f[i + 1][j - 1] + (100 - p)% * f[i][j]; $

乘二:\(f[i + 1][j * 2] = f[i + 1][j * 2] + p\% * (f[i][j] + 1);\)

#include<bits/stdc++.h>
using namespace std;
int x, k;
double p, p1;
double f[300][300];
int main() {
    scanf("%d%d%lf", &x, &k, &p);
    p /= 100, p1 = 1.0 - p;
    for (int i = 0; i <= k; i ++)
        for (int j = x + i; j % 2 == 0; j /= 2)
            f[0][i] ++;
    for (int i = 0; i < k; i ++)
        for (int j = 0; j <= k; j ++) {
            if (j)
                f[i + 1][j - 1] += p1 * f[i][j]; // + 1
            if (j * 2 <= k)
                f[i + 1][j * 2] += p * (f[i][j] + 1); // * 2
        }
    printf("%.10f\n", f[k][0]);
    return 0;
}

原文地址:https://www.cnblogs.com/wjnclln/p/10781613.html

时间: 2024-08-12 20:27:47

CF 441E Valera and Number的相关文章

CF(441D Valera and Swaps)置换群

题意:1-n的一个排列 p1,?p2,?...,?pn,f(p)的定义是此排列要交换最少的数对可以回到原排列1,2,3,4...n.给一个排列p,要将其变换成f值为m的排列,问至少要交换几个数对,并输出字典序最小的那组答案. 解法:处理出所有的置换群,求出环数k,此时f值为n-k.然后判断n-k和m的大小,分为两种操作 1.加环,这个是在任意元素个数大于1的环内交换任意两个数都可以做到加环 2.减环,交换任意两个环的任意两个元素,就可以做到将两个环连接起来 题目要求是输出字典序最小,那么就暴力搞

CF 546D Soldier and Number Game

Describe Two soldiers are playing a game. At the beginning first of them chooses a positive integer n and gives it to the second soldier. Then the second one tries to make maximum possible number of rounds. Each round consists of choosing a positive

CF 1215 B The Number of Products(思维题)

链接:https://codeforces.com/contest/1215/problem/B You are given a sequence a1,a2,…,ana1,a2,…,an consisting of nn non-zero integers (i.e. ai≠0ai≠0). You have to calculate two following values: the number of pairs of indices (l,r)(l,r) (l≤r)(l≤r) such t

cf B Very Beautiful Number

题意:给你两个数p和x,然后让你找出一个长度为p的数,把它的最后移到最前面之后得到的数是原来数字的x倍,有很多这样的数取最小. 思路:枚举最后一位,然后就可以推出整个的一个数,然后比较得到的数的第一个数字和枚举的数字是否相等既可以. 1 #include <cstdio> 2 #include <cstring> 3 #include <cmath> 4 #include <algorithm> 5 using namespace std; 6 7 int

cf C. George and Number

http://codeforces.com/problemset/problem/387/C 题意:给你一个大数,让你求个集合,可以通过操作得到这个数,求集合中个数最大值,操作 :从集合中任意取两个数,大的数放在前面小的数放在后面组成一个数在重新放入集合中,经过重复的操作,集合中只剩一个数,这个数就是给你的数. 思路:要求个数最大,可以让这个大数的每一个数字为集合中的一个数,但是集合中不能有0,所以在连续的0前面要连着一个非零的数. 1 #include <cstdio> 2 #include

[CF441E]Valera and Number

题意:给定$x,k,p$和一份伪代码,伪代码大致是循环$k$次,每次有$p\%$的概率把$x$乘$2$,有$(100-p)\%$的概率把$x$加$1$,问最后在二进制下$x$的末尾期望$0$个数 鸽了好久...今天来补一下 设$f_{i,j}$表示循环$i$次后$x+j$的末尾期望$0$个数 乘$2$:相当于把最后加上的$j$也乘$2$,所以$f_{i+1,2j}+=\dfrac{p}{100}(f_{i,j}+1)$ 加$1$:相当于上一轮加$1$,所以$f_{i+1,j}+=(1-\dfra

2月每日

2.6 Alyona and Triangles 凸包,双指针,最大面积三角形 1 #include <cstdio> 2 #include <algorithm> 3 #include <cmath> 4 #include <vector> 5 using namespace std; 6 //lrj计算几何模板 7 8 typedef long long LL; 9 const int maxn = 5555; 10 11 struct Point 12

【Leetcode】17、Letter Combinations of a Phone Number

题目 Given a string containing digits from 2-9 inclusive, return all possible letter combinations that the number could represent. A mapping of digit to letters (just like on the telephone buttons) is given below. Note that 1 does not map to any letter

nginx事件模块 -- 第二篇

微信公众号:郑尔多斯关注可了解更多的Nginx知识.任何问题或建议,请公众号留言;关注公众号,有趣有内涵的文章第一时间送达! 事件机制 上一篇文件我们简单的介绍了ngx_event_block()函数的功能,这个函数用于解析events指令,引入事件机制.其实真正的工作是在ngx_event_core_module中完成的,这个模块可以解析use,work_connections等指令,这些指令用于控制nginx事件机制的一些参数.上一篇文章中我们也提到过执行ngx_event_block()函