[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 ...
随机推荐
- C语言进阶之路(一)----C语言的内存四区模型
内存四区模型:操作系统给C/C++编写的程序分配内存,通常将分配的内存划分为以下四个区域:1.栈区:存放局部变量,用完由操作系统自动释放2.堆区:动态分配给程序的内存区域,由程序员手动释放3.数据区: ...
- 百度富文本Ueditor编辑器的使用
往在web开发的时候,尤其是在网站开发后台管理系统的时候经常会使用到富文本编辑器,这里我们来使用百度提供的富文本编辑器UEditor,以提高我们的开发效率 UEditor官网下载地址:https:// ...
- 使用dbeaver查mysql的表会导致锁表的问题
查询完成之后接着需要使用rollback,不然其它session没法执行语句.
- 21 python的魔法方法(转)
魔法方法 含义 基本的魔法方法 __new__(cls[, ...]) 1. __new__ 是在一个对象实例化的时候所调用的第一个方法2. 它的第一个参数是这个类,其他的参数是用来直接传递给 _ ...
- Linux基础命令---cancel取消打印任务
cancel cancel指令用来取消已经存在的打印任务. 此命令的适用范围:RedHat.RHEL.Ubuntu.CentOS.Fedora.openSUSE.SUSE. 1.语法 ...
- c语言格式化打印
printf的格式化打印 unsigned int ------------------- %u 打印无符号数 int ----------- ...
- sliver
import 'package:flutter/material.dart';import 'package:xxx/bloc/bloc.dart';import 'package:xxx/model ...
- Html img 标签
Html img 标签 <html> <body> <!-- img 标签用于显示图片.src="xxx.jpg" 指定图片路径名称--> &l ...
- Android中的task和stack
今天在重新理了一遍intent的过程中发现task是一个神奇的东西,而它又和stack有着很深的联系.task顾名思义是一个任务,但是这个任务可不一定只是来自一个app,比如我用微信来发一张图片,那么 ...
- Bulbs【暴力?】
问题 B: Bulbs 时间限制: 1 Sec 内存限制: 128 MB 提交: 216 解决: 118 [提交] [状态] [命题人:admin] 题目描述 Greg has an m × n ...