ZOJ-3162-To Go or Not to Go
来源:互联网 发布:数据库实用教程答案 编辑:程序博客网 时间:2024/06/08 04:29
点击打开题目链接
<span style="font-size:18px;"># include <cstdio># include <cstring># include <iostream>using namespace std;double dp[30][2];void init(){ memset(dp,0,sizeof(dp)); for(int i = 1;i < 30;i++){ dp[i][1] = dp[i-1][1] + dp[i-1][0] + (1<<i-1); dp[i][0] = dp[i-1][1] + dp[i-1][0]; }}double fun(int n){ int cnt = 0;double sum = 0; for(int i = 29;i >= 0;i--){ if(n &(1<<i)){ sum += dp[i+1][0]; sum += (double)(1<<i) * cnt; cnt++; } } return sum + cnt;}double calc(int a,int b){ int bit1,bit2; double cnt=b-a+1,sum=0; for(int i=29;i>=0;i--){ if(a&(1<<i)){ bit1=i; break; } } for(int i=29;i>=0;i--){ if(b&(1<<i)){ bit2=i; break; } } if(bit2-bit1==0){ double num=fun(b)-fun(a-1); sum = num/(bit1+1); } else{ int x = (1<<(bit1+1)) - 1; double num=fun(x) - fun(a-1); sum = num/(bit1+1); x = (1<<bit2); num = fun(b)-fun(x) + 1; sum += num/(bit2+1); } for(int i=bit1+2;i<=bit2;i++) sum+=dp[i][1]/i; return sum/cnt;}int main(){ int t; init(); scanf("%d",&t); while(t--){ int a,b; scanf("%d%d",&a,&b); printf("%.6lf\n",calc(a,b)); } return 0;}</span>
0 0
- zoj 3162 To Go or Not to Go 数位DP
- ZOJ-3162-To Go or Not to Go
- to go or not to go
- zju 3162 To Go or Not to Go
- 328. Not to advance is to go back. 不进则退
- ZOJ-1236 Eat or Not to Eat?
- GO TO SHEN ZHEN
- Ready To Go!
- JICQ,Ready to go...
- Go to hell !!!
- 关于go to 语句
- A list to go
- long way to go
- Windows 8 to Go
- 制作 Windows8 to Go
- The way to go !
- Go on to ISP
- 【GO】Ready To Work
- easyui 动态添加列
- 【bzoj4064】[Cerc2012]The Dragon and the knights
- CS架构
- c++中的const
- 数据库课堂笔记
- ZOJ-3162-To Go or Not to Go
- H.264官方软件JM源代码简单分析-编码器lencod
- LightOJ 1047 - Neighbor House (dp)
- VS 2015 使用经验
- 第十一周项目1 - 二叉树算法验证(3)中序线索化二叉树的算法验证
- hdu 1247 Hat’s Words
- ping命令使用及返回总结
- 牛客网 | 链表中环的入口结点
- 表达树构造