http://acm.scau.edu.cn:8000/uoj/mainMenu.html

18113 Secret Book of Kungfu

该题有题解

时间限制:1000MS  内存限制:65535K
提交次数:0 通过次数:0

题型: 编程题   语言: 不限定

Description

    Uncle Big is acknowledged as a master of kung fu. But he doesn't think so. He thinks that there are many other unknown
experts in the world. So Uncle Big devotes all his life to find the highest realm of kung fu.
During a chance, Uncle Big discover a secret book of kungfu in a cave. But the book is broken and losts many pages. What's
worst, there's only some numbers writted on the book. After studying the book years and years, Uncle Big discover that all
this numbers have a common feature that, the decimal notation of a number is a substring of its binary notation. So Uncle
Big want to restore the book, in order to better understand it. Before doing this, Uncle Big has to know how many such numbers
between l and r (inclusive).
But now Uncle Big is so exciting because of this discovering, and has gone to race boat. Can you help him?

输入格式

    The input file begins with an integer T (T <= 10000) in one row indicating the number of test case. Then T test cases
follows.
Each test case contains one line with two non-negetive integer l and r (l <= r <= 1000000000000000(1e15) ).

输出格式

    For each test case, print one line with a integer as answer.

输入样例

1
1 1000

输出样例

8

提示

"1", "0", "10", "01", "101" are the substring of "101", but "11", "00" are not.

考虑按位DFS后再暴力判断,然后发现总数只有283个,记得加上0,就284个。打个表二分查找就好。

dfs数字的话,一般就是dfs(cur * 10 + 0),这个数位进位后,然后加上想要的数字

#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <algorithm>
#define IOS ios::sync_with_stdio(false)
using namespace std;
#define inf (0x3f3f3f3f)
typedef long long int LL; #include <iostream>
#include <sstream>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <string>
LL L, R;
int ans;
char str_bin[];
char num[];
int lenstr;
void bin(LL n) {
if (n / ) bin(n / );
str_bin[++lenstr] = n % + '';
}
LL biao[ + ];
int lenbiao;
void dfs(LL cur) {
if (cur >= L && cur <= R) {
lenstr = ;
bin(cur);
int k = ;
LL t = cur;
while (t / > ) {
num[++k] = t % + '';
t /= ;
}
num[++k] = t + '';
num[k + ] = '\0';
str_bin[lenstr + ] = '\0';
// cout << str_bin + 1 << endl; reverse(num + , num + + k);
// cout << num + 1 << endl;
// cout << endl;
char *p = strstr(str_bin + , num + );
if (p != NULL)
biao[++lenbiao] = cur;
}
if (cur > R) return;
dfs(cur * );
dfs(cur * + );
}
void work() {
cin >> L >> R;
if (L > R) swap(L, R);
int posR = lower_bound(biao + , biao + + lenbiao, R) - biao;
int posL = lower_bound(biao + , biao + + lenbiao, L) - biao;
if (biao[posL] == L && biao[posR] == R) {
cout << posR - posL + << endl;
} else if (biao[posL] == L && biao[posR] != R) {
cout << posR - posL << endl;
} else if (biao[posL] != L && biao[posR] == R) {
cout << posR - posL + << endl;
} else {
cout << posR - posL << endl;
}
}
void init() {
biao[++lenbiao] = ;
L = ;
R = 1e15L;
dfs();
sort(biao + , biao + + lenbiao);
}
int main() {
#ifdef local
freopen("data.txt","r",stdin);
#endif
IOS;
init();
int t;
cin >> t;
while (t--) work();
return ;
}

最新文章

  1. Linux disk_partition_dev_马士兵_note
  2. cpio命令用法
  3. SpringMVC学习--springmvc和mybatis整合
  4. 浅析初等贪吃蛇AI算法
  5. hdu 1860统计字符
  6. InterBase数据库迁移到MySQL(数据导出)
  7. 3D语音天气球(源码分享)——在Unity中使用Android语音服务
  8. bzoj 1806 [Ioi2007]Miners 矿工配餐(DP)
  9. svn强制提交备注信息
  10. 泛泰A900 刷4.4中国民营TWRP2.7.1.1版本 支持自己主动识别移动版本号(世界上第一)
  11. python 之路,200行Python代码写了个打飞机游戏!
  12. java的ArrayList源码摘要
  13. Python_建造者模式
  14. Linux 抓包工具:tcpdump
  15. 莫烦tensorflow(1)-训练线性函数模型
  16. CPP/类/成员函数访问权限
  17. linux每天一小步---cat命令详解
  18. flume学习以及ganglia(若是要监控hive日志,hive存放在/tmp/hadoop/hive.log里,只要运行过hive就会有)
  19. 使用python登录CNZZ访问量统计网站,然后获取相应的数据
  20. (数据科学学习手札49)Scala中的模式匹配

热门文章

  1. 安装python解释器
  2. 【应用】SVG动态 时钟
  3. MFC中显示一张位图
  4. ubuntu系统,关于源(source)的配置
  5. 想要删除table的某一行的js写法
  6. 安装openstack出现的问题及解决
  7. 1.131.15 Sqoop导出数据Export使用
  8. 1.5 sqoop安装及基本使用
  9. 【eclipse插件开发实战】 Eclipse插件开发6——eclipse在线翻译插件Translator开发实例详解
  10. AS3 滤镜相关