[Codeforces441E]Valera and Number
Problem
给定一个数x,有p%的概率乘2,有1-p%的概率加1,问操作k次,其二进制数下末尾零的个数的期望。
Solution
每次操作只会影响到最后的8位
我们用dp[i][j]表示i个操作后,后面的操作还需要加j
对于+1的操作:dp[i][j-1]+=dp[i-1][j](1-p)
对于2的操作:dp[i][j2]+=(dp[i-1][j]+1)p
Notice
需要预处理
Code
#include<cmath>
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
#define sqz main
#define ll long long
#define reg register int
#define rep(i, a, b) for (reg i = a; i <= b; i++)
#define per(i, a, b) for (reg i = a; i >= b; i--)
#define travel(i, u) for (reg i = head[u]; i; i = edge[i].next)
const int INF = 1e9;
const double eps = 1e-6, phi = acos(-1.0);
ll mod(ll a, ll b) {if (a >= b || a < 0) a %= b; if (a < 0) a += b; return a;}
ll read(){ ll x = 0; int zf = 1; char ch; while (ch != '-' && (ch < '0' || ch > '9')) ch = getchar();
if (ch == '-') zf = -1, ch = getchar(); while (ch >= '0' && ch <= '9') x = x * 10 + ch - '0', ch = getchar(); return x * zf;}
void write(ll y) { if (y < 0) putchar('-'), y = -y; if (y > 9) write(y / 10); putchar(y % 10 + '0');}
double p;
int x, k;
double f[205][205];
int sqz()
{
int x = read(), k = read();
scanf("%lf", &p), p /= 100;
rep(i, 0, k)
{
int t = x + i;
while (1)
{
if (t & 1) break;
f[0][i]++;
t /= 2;
}
}
rep(i, 1, k)
{
memset(f[i], 0, sizeof f[i]);
rep(j, 0, k)
{
if (j) f[i][j - 1] += f[i - 1][j] * (1 - p);
if (j * 2 <= k) f[i][j * 2] += (f[i - 1][j] + 1) * p;
}
}
printf("%.10lf\n", f[k][0]);
}
[Codeforces441E]Valera and Number的更多相关文章
- [CodeForces-441E]Valera and Number
题目大意: 给你一个数x,进行k次操作: 1.有p%的概率将x翻倍: 2.有1-p%的概率将x加1. 问最后二进制下x末尾0个数的期望. 思路: 动态规划. 由于k只到200,所以每次修改只与最后8位 ...
- 【Codeforces441E】Valera and Number [DP]
Valera and Number Time Limit: 20 Sec Memory Limit: 512 MB Description Input Output Sample Input 5 3 ...
- CodeForces - 441E:Valera and Number (DP&数学期望&二进制)
Valera is a coder. Recently he wrote a funny program. The pseudo code for this program is given belo ...
- CF 441E Valera and Number
CF 441E Description 一共执行\(k\)次,每次有\(p\%\)把\(x * 2\),有\((100 - p)\%\)把\(x + 1\).问二进制下\(x\)末尾期望\(0\)的个 ...
- [CF441E]Valera and Number
题意:给定$x,k,p$和一份伪代码,伪代码大致是循环$k$次,每次有$p\%$的概率把$x$乘$2$,有$(100-p)\%$的概率把$x$加$1$,问最后在二进制下$x$的末尾期望$0$个数 鸽了 ...
- Codeforces刷题计划
Codeforces刷题计划 已完成:-- / -- [Codeforces370E]370E - Summer Reading:构造:(给定某些数,在空白处填数,要求不下降,并且相邻差值<=1 ...
- Codeforces Round 252 (Div. 2)
layout: post title: Codeforces Round 252 (Div. 2) author: "luowentaoaa" catalog: true tags ...
- CF 369C . Valera and Elections tree dfs 好题
C. Valera and Elections The city Valera lives in is going to hold elections to the city Parliament ...
- [Codeforces Round #237 (Div. 2)] A. Valera and X
A. Valera and X time limit per test 1 second memory limit per test 256 megabytes input standard inpu ...
随机推荐
- Substrate 使用
1.安装 首先安装sdk,按官网教程http://www.cydiasubstrate.com/id/73e45fe5-4525-4de7-ac14-6016652cc1b8/ http://asdk ...
- 安装caffe-ssd或者caffe时make all,make pycaffe,make test运行慢的问题
之所有运行慢,是因为没有在这三条语句后面加上 -j,即没用全部的进程运行,不加-j 表示用单一进程运行,加上-j5表示用5个进程,-j不带数字表示用所有进程
- Linux 安装 java
由于各Linux开发厂商的不同,因此不同开发厂商的Linux版本操作细节也不一样,今天就来说一下CentOS下JDK的安装: 方法一:手动解压JDK的压缩包,然后设置环境变量 1.在/usr/目录下创 ...
- “Nested exception: 前言中不允许有内容"错误处理
最近在做一个小项目,使用org.dom4j.DocumentHelper.parseText方法时一直报错”Nested exception: 前言中不允许有内容",这个parseText解 ...
- MySQL插入更新_ON DUPLICATE KEY UPDATE
前提:操作的表具有主键或唯一索引 INSERT INTO:表中不存在对应的记录,则插入:若存在对应的记录,则报错: INSERT INTO IGNORE:表中不存在对应的记录,则插入:若存在对应的记录 ...
- JAVA值传递之基本数据类型和引用数据类型
#1.基本数据类型值传递 package 经典小Demo.值传递; public class Test { public static void main(String[] args) { int a ...
- button theme
children:[ButtonTheme.bar( child:ButtonBar( children:[ FlatButton... ], ),), ]
- log4net架构、配置、使用
架构说明 架构说明 上图是官方文档的提供的代码组织. Log4net的核心组件有: Logger, Appender, Filter, Layout, Object Render, Logger介绍 ...
- CSS布局学习(三) - Normal Flow 正常布局流(官网直译)
默认情况下,元素是如何布局? 首先,取得元素的内容,加上内边距(padding),边框(border),外边距(margin)放在一个盒子中 - 这就是我们之前看到的盒子模型 默认情况下,块级元素的内 ...
- 线程(六)之LOCK和synchronized
在java.util.concurrent.locks包中有很多Lock的实现类,常用的有ReentrantLock.ReadWriteLock(实现类ReentrantReadWriteLock), ...