[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-\dfrac{p}{100})f_{i,j+1}$

因为第一维每次只增加$1$所以用滚动数组

#include<stdio.h>
#include<string.h>
double f[2][410];
int main(){
	int x,k,i,j,t;
	double p;
	scanf("%d%d%lf",&x,&k,&p);
	p*=.01;
	for(i=0;i<=k;i++){
		for(j=x+i;~j&1;j>>=1)f[0][i]+=1;
	}
	t=0;
	for(i=0;i<k;i++){
		memset(f[t^1],0,sizeof(f[t^1]));
		for(j=0;j<=k;j++){
			f[t^1][j<<1]+=(f[t][j]+1.)*p;
			f[t^1][j]+=f[t][j+1]*(1.-p);
		}
		t^=1;
	}
	printf("%.7lf",f[t][0]);
}

原文地址:https://www.cnblogs.com/jefflyy/p/8394845.html

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

[CF441E]Valera and Number的相关文章

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 +

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

codeforces A. Valera and Plates 题解

Valera is a lazy student. He has m clean bowls and k clean plates. Valera has made an eating plan for the next n days. As Valera is lazy, he will eat exactly one dish per day. At that, in order to eat a dish, he needs exactly one clean plate or bowl.

Codeforces Round #216 (Div. 2)---C. Valera and Elections

The city Valera lives in is going to hold elections to the city Parliament. The city has n districts and n?-?1 bidirectional roads. We know that from any district there is a path along the roads to any other district. Let's enumerate all districts in

Valera and Fruits

Description Valera loves his garden, where n fruit trees grow. This year he will enjoy a great harvest! On the i-th tree bi fruit grow, they will ripen on a day number ai. Unfortunately, the fruit on the tree get withered, so they can only be collect

Codeforces 124A - The number of positions

题目链接:http://codeforces.com/problemset/problem/124/A Petr stands in line of n people, but he doesn't know exactly which position he occupies. He can say that there are no less than a people standing in front of him and no more than b people standing b

17. Letter Combinations of a Phone Number

Given a digit string, 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. Input:Digit string "23" Output: ["ad", "ae", &q

实现一个函数clone,使JavaScript中的5种主要的数据类型(包括Number、String、Object、Array、Boolean)进行值复制

实现一个函数clone,可以对JavaScript中的5种主要的数据类型(包括Number.String.Object.Array.Boolean)进行值复制. 1 /** 对象克隆 2 * 支持基本数据类型及对象 3 * 递归方法 */ 4 function clone(obj) { 5 var o; 6 switch (typeof obj) { 7 case "undefined": 8 break; 9 case "string": o = obj + &q

解决sqoop报错Invalid number; item = ITEM_UNICODE

报错栈: java.sql.SQLException: Invalid number; item = ITEM_UNICODE at com.intersys.jdbc.SysList.getInt(SysList.java:1735) at com.intersys.jdbc.CacheResultSet.getInt(CacheResultSet.java:247) at org.apache.sqoop.lib.JdbcWritableBridge.readInteger(JdbcWrit