题意:

给你n个区间,在每个区间里各取一个数(随机取),求这n个数中超过K%的数是首位为1数的概率

分析:

dp[i][j]取前i个数,有j个是首位为1的数的概率

易知,dp[i][j]=dp[i-1][j]*(1-p[i])+dp[i-1][j-1]*p[i];

现在关键是求p[i],第i个区间首位为1的数出现的概率,用数位统计一下即可

  1. #include <map>
  2. #include <set>
  3. #include <list>
  4. #include <cmath>
  5. #include <queue>
  6. #include <stack>
  7. #include <cstdio>
  8. #include <vector>
  9. #include <string>
  10. #include <cctype>
  11. #include <complex>
  12. #include <cassert>
  13. #include <utility>
  14. #include <cstring>
  15. #include <cstdlib>
  16. #include <iostream>
  17. #include <algorithm>
  18. using namespace std;
  19. typedef pair<int,int> PII;
  20. typedef long long ll;
  21. #define lson l,m,rt<<1
  22. #define pi acos(-1.0)
  23. #define rson m+1,r,rt<<11
  24. #define All 1,N,1
  25. #define read freopen("in.txt", "r", stdin)
  26. const ll INFll = 0x3f3f3f3f3f3f3f3fLL;
  27. const int INF= 0x7ffffff;
  28. const int mod = ;
  29. ll sum[],a[];
  30. double dp[][],p[];
  31. int bit[],n,k;
  32. void init(){
  33. sum[]=;
  34. for(int i=;i<=;++i)
  35. sum[i]=sum[i-]*;
  36. }
  37. ll countsum(int l){
  38. ll total=;
  39. for(int i=;i<=l;++i)
  40. total+=sum[i];
  41. return total;
  42. }
  43. //统计首位为1数的数量
  44. ll countone(ll x){
  45. if(x==)return ;
  46. init();
  47. int len=;
  48. while(x){
  49. bit[++len]=x%;
  50. x/=;
  51. }
  52. if(bit[len]>){
  53. return countsum(len-);
  54. }
  55. else{
  56. ll tmp=countsum(len-);
  57. a[]=;
  58. for(int i=;i<=len-;++i)
  59. a[i]=a[i-]+bit[i]*sum[i-];
  60. tmp+=a[len-]+;
  61. return tmp;
  62. }
  63. }
  64. int main()
  65. {
  66. ll l,r;
  67. while(~scanf("%d",&n)){
  68. for(int i=;i<=n;++i){
  69. scanf("%I64d%I64d",&l,&r);
  70. ll tmp=countone(r)-countone(l-);
  71. //cout<<tmp<<endl;
  72. p[i]=1.0*tmp/(r-l+);
  73. //cout<<p[i]<<endl;
  74. }
  75. dp[][]=p[];
  76. dp[][]=1.0-p[];
  77. for(int i=;i<=n;++i)
  78. for(int j=;j<=i;++j){
  79. dp[i][j]+=dp[i-][j]*(1.0-p[i]);
  80. if(j>)
  81. dp[i][j]+=dp[i-][j-]*p[i];
  82. }
  83. scanf("%d",&k);
  84. double ans=0.0;
  85. for(int j=;j<=n;++j)
  86. if(j>=(1.0*n*k/))
  87. ans+=dp[n][j];
  88. printf("%.15lf\n",ans);
  89. }
  90. return ;
  91. }

CodeForces 54C-First Digit Law(数位,概率dp)的更多相关文章

  1. Codeforces 678E. Another Sith Tournament(概率DP,状压)

    Codeforces 678E. Another Sith Tournament 题意: n(n<=18)个人打擂台赛,给定任意两人对决的胜负概率,比赛规则:可指定一人作为最开始的擂主,每次可指 ...

  2. Codeforces B. Bad Luck Island(概率dp)

    题目描述: Bad Luck Island time limit per test 2 seconds memory limit per test 256 megabytes input standa ...

  3. Codeforces 148D Bag of mice:概率dp 记忆化搜索

    题目链接:http://codeforces.com/problemset/problem/148/D 题意: 一个袋子中有w只白老鼠,b只黑老鼠. 公主和龙轮流从袋子里随机抓一只老鼠出来,不放回,公 ...

  4. Codeforces 167B Wizards and Huge Prize(概率dp)

    题意: n个人,开始有一个容量为k得背包,击败一个人背包可以获得一定容量或得到一个财富(放入背包内),给出击败每个人的概率,求至少击败l个人,且背包容量大于获得的总财富值的概率 分析: 状态好确定,d ...

  5. Codeforces 601C Kleofáš and the n-thlon 概率dp

    Kleofáš and the n-thlon 我们可以用dp算出比当前这个人得分少的概率, 然后人数乘概率就好啦. dp[ i ][ j ]表示进行了 i 轮 得分为 j 的概率, 因为每个人都是独 ...

  6. Codeforces 280C Game on tree【概率DP】

    Codeforces 280C Game on tree LINK 题目大意:给你一棵树,1号节点是根,每次等概率选择没有被染黑的一个节点染黑其所有子树中的节点,问染黑所有节点的期望次数 #inclu ...

  7. codeforces#1139D. Steps to One (概率dp+莫比乌斯反演)

    题目链接: http://codeforces.com/contest/1139/problem/D 题意: 在$1$到$m$中选择一个数,加入到一个初始为空的序列中,当序列的$gcd$和为$1$时, ...

  8. 2018.12.12 codeforces 931E. Game with String(概率dp)

    传送门 感觉这题难点在读懂题. 题目简述:给你一个字符串s,设将其向左平移k个单位之后的字符串为t,现在告诉你t的第一个字符,然后你可以另外得知t的任意一个字符,求用最优策略猜对k的概率. 解析: 预 ...

  9. CodeForces 55D "Beautiful numbers"(数位DP+离散化处理)

    传送门 参考资料: [1]:CodeForces 55D Beautiful numbers(数位dp&&离散化) 我的理解: 起初,我先定义一个三维数组 dp[ i ][ j ][ ...

  10. Codeforces #548 (Div2) - D.Steps to One(概率dp+数论)

    Problem   Codeforces #548 (Div2) - D.Steps to One Time Limit: 2000 mSec Problem Description Input Th ...

随机推荐

  1. REST_FRAMEWORK加深记忆-加了API_ROOT及超链接的CASE

    urls.py from django.conf.urls import url from rest_framework.urlpatterns import format_suffix_patter ...

  2. REST_FRAMEWORK加深记忆-第二次练习官方文档2

    优化前和优化后的代码,融在一起,能看看进化的过程. MODELS.PY from django.db import models from pygments.lexers import get_all ...

  3. String及其他

    String 以下例开始讲解String public class StringDemo { public static void main(String[] args) { // String s ...

  4. 解决maven-dependency-plugin (goals "copy-dependencies", "unpack") is not supported by m2e.错误

    POM文件报错maven-dependency-plugin (goals "copy-dependencies", "unpack") is not supp ...

  5. 【互联网那些事儿】小度 i 耳目

    关于这个产品是什么,大家自行度. 这里我主要想说的,是百度关于这个产品的一点……呃,“卖萌”的介绍语言. 小度i耳目常见问题 问:为什么叫小度i耳目呢,貌似不太好记忆. 答:名字嘛都是父母起的,不过时 ...

  6. hadoop2.2.0集群搭建与部署

    原创文章,转载请注明: 转载自http://www.cnblogs.com/tovin/p/3818908.html 一.安装环境 1.系统环境 CentOS  6.4 2.集群机器节点ip 节点一i ...

  7. Java中Integer的源码学习

      一.开始 public final class Integer extends Number implements Comparable<Integer> 1).由于类修饰符中有关键字 ...

  8. LR_问题_控制器不能使用定义的负载生成器

    问题描述 在controller 中设置了面向目标的方案后 执行提示 The target you defined cannot be reached.the LoadRunner Controlle ...

  9. C语言复习笔记-17种小算法-解决实际问题

    判断日期为一年中的第几天(考虑闰年) 1 /* 2 * 计算该日在本年中是第几天,注意闰年问题 3 * 以3月5日为例,应该先把前两个月的加起来,然后再加上5天即本年的第几天 4 * 特殊情况,闰年且 ...

  10. Git教程之版本回退(4)

    现在,我们已经学会了修改文件,然后把修改提交到Git版本库,现在再次修改readme.txt文件如下: