Codeforces Beta Round #50, problem: (C) First Digit Law 数位DP
来源:互联网 发布:阿里云 免费 开通码 编辑:程序博客网 时间:2024/05/21 09:03
题意:找出给定区间内首数字为1的数字。
做法:基本数位DP,可是出现了一堆小错误 。。。
#include<cstdio>#include<cstring>#define LL long longconst int LMT=1002;LL have[LMT],tem[LMT],num[20],left[LMT],right[LMT];/***********一开始把统计区间内符合的数字给搞错了****/double dp[LMT];void init(void){ int i; LL use = 1; //fuck 这里的use tem[1]=1; for(i=2, use=10;i<20; ++i, use*=10) tem[i]=use+tem[i-1];}LL treat(LL x){ if(0 == x)return 0; LL res=0,rev_x=0; int i = 0, end; do num[i++]=x%10; while(x/=10); res+=tem[i-1];end=i; if (num[end - 1] > 1) return tem[end]; for(i = end - 2; i >=0; --i) { rev_x *= 10; rev_x += num[i]; } return res + rev_x + 1;}int main(void){ int N,i,j, k; double ans=0; init(); scanf("%d",&N); for(i=1;i<=N;i++) { scanf("%I64d%I64d",&left[i],&right[i]); have[i]=treat(right[i])-treat(left[i] - 1); } scanf("%d",&k); dp[0]=1.0; for(i=1;i<=N;++i) for(j=i;j>=0;--j) { dp[j]=dp[j]*(right[i]-left[i]+1-have[i])/(right[i]-left[i]+1); if(j) dp[j]+=dp[j-1]*have[i]/(right[i]-left[i]+1); } for(i=0;i<=N;i++) if(i*100>=N*k)//这里都会错啊,没乘100 ans += dp[i]; printf("%.15f\n",ans); return 0;}
- Codeforces Beta Round #50, problem: (C) First Digit Law 数位DP
- Codeforces Beta Round #50 C. First Digit Law(概率dp,好题)
- Codeforces 54C First Digit Law 数位dp+概率dp
- codeforces 54C First Digit Law (数位dp+概率dp+背包模型)
- Codeforces 54C First Digit Law —— 概率DP
- Codeforces Beta Round #51 D 数位DP
- Codeforces Beta Round #51 D 数位DP
- Codeforces Beta Round #13, problem: (C) Sequence DP
- Codeforces Beta Round #90, problem: (C) Education Reform DP
- Codeforces Beta Round #77 (Div. 1 Only), problem: (B) Lucky Numbers 数位DP+剪枝DFS+贪心
- Codeforces Beta Round #2 C. Commentator problem
- Codeforces Beta Round #51 D. Beautiful numbers (数位dp)
- Codeforces Beta Round #51---D. Beautiful numbers(数位dp, 巧妙)
- Codeforces Beta Round #51 D. Beautiful numbers(数位dp)
- Codeforces Beta Round #8 E. Beads(数位DP)
- Codeforces Beta Round #8 E. Beads (数位dp)
- Codeforces Beta Round #17 C. Balance DP
- Codeforces Beta Round #71 C【KMP+DP】
- csapp2e 家庭作业 2.80
- 网络对讲机C#服务器 Android客户端(二) C#服务器代码分析
- asp.net 基本语法
- iOS应用内支付(IAP)的那些坑
- 复制网站内容 本程序将网站“www.baidu.com”首页的内容复制保存在文件test.html中。
- Codeforces Beta Round #50, problem: (C) First Digit Law 数位DP
- asp.net代码写法
- bug
- 如何让IIS显示错误明细
- 利用memcpy分割整型数组
- 这几个时间你是怎么过的?
- 分页SQL与SQL server 重置自增ID
- VC调试方法大全
- delphi2010中使用DataSnape做三层保存jpg图片