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

18113 Secret Book of Kungfu

该题有题解

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

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

Description

  1. Uncle Big is acknowledged as a master of kung fu. But he doesn't think so. He thinks that there are many other unknown
  2. experts in the world. So Uncle Big devotes all his life to find the highest realm of kung fu.
  3. 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
  4. worst, there's only some numbers writted on the book. After studying the book years and years, Uncle Big discover that all
  5. this numbers have a common feature that, the decimal notation of a number is a substring of its binary notation. So Uncle
  6. Big want to restore the book, in order to better understand it. Before doing this, Uncle Big has to know how many such numbers
  7. between l and r (inclusive).
  8. But now Uncle Big is so exciting because of this discovering, and has gone to race boat. Can you help him?

输入格式

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

输出格式

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

输入样例

  1. 1
  2. 1 1000

输出样例

  1. 8

提示

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

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

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

  1. #include <cstdio>
  2. #include <cstdlib>
  3. #include <cstring>
  4. #include <cmath>
  5. #include <algorithm>
  6. #define IOS ios::sync_with_stdio(false)
  7. using namespace std;
  8. #define inf (0x3f3f3f3f)
  9. typedef long long int LL;
  10.  
  11. #include <iostream>
  12. #include <sstream>
  13. #include <vector>
  14. #include <set>
  15. #include <map>
  16. #include <queue>
  17. #include <string>
  18. LL L, R;
  19. int ans;
  20. char str_bin[];
  21. char num[];
  22. int lenstr;
  23. void bin(LL n) {
  24. if (n / ) bin(n / );
  25. str_bin[++lenstr] = n % + '';
  26. }
  27. LL biao[ + ];
  28. int lenbiao;
  29. void dfs(LL cur) {
  30. if (cur >= L && cur <= R) {
  31. lenstr = ;
  32. bin(cur);
  33. int k = ;
  34. LL t = cur;
  35. while (t / > ) {
  36. num[++k] = t % + '';
  37. t /= ;
  38. }
  39. num[++k] = t + '';
  40. num[k + ] = '\0';
  41. str_bin[lenstr + ] = '\0';
  42. // cout << str_bin + 1 << endl;
  43.  
  44. reverse(num + , num + + k);
  45. // cout << num + 1 << endl;
  46. // cout << endl;
  47. char *p = strstr(str_bin + , num + );
  48. if (p != NULL)
  49. biao[++lenbiao] = cur;
  50. }
  51. if (cur > R) return;
  52. dfs(cur * );
  53. dfs(cur * + );
  54. }
  55. void work() {
  56. cin >> L >> R;
  57. if (L > R) swap(L, R);
  58. int posR = lower_bound(biao + , biao + + lenbiao, R) - biao;
  59. int posL = lower_bound(biao + , biao + + lenbiao, L) - biao;
  60. if (biao[posL] == L && biao[posR] == R) {
  61. cout << posR - posL + << endl;
  62. } else if (biao[posL] == L && biao[posR] != R) {
  63. cout << posR - posL << endl;
  64. } else if (biao[posL] != L && biao[posR] == R) {
  65. cout << posR - posL + << endl;
  66. } else {
  67. cout << posR - posL << endl;
  68. }
  69. }
  70. void init() {
  71. biao[++lenbiao] = ;
  72. L = ;
  73. R = 1e15L;
  74. dfs();
  75. sort(biao + , biao + + lenbiao);
  76. }
  77. int main() {
  78. #ifdef local
  79. freopen("data.txt","r",stdin);
  80. #endif
  81. IOS;
  82. init();
  83. int t;
  84. cin >> t;
  85. while (t--) work();
  86. return ;
  87. }

18113 Secret Book of Kungfu 按位DFS的更多相关文章

  1. hdoj 1342 Lotto【dfs】

    Lotto Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submi ...

  2. hdu 5676 ztr loves lucky numbers(dfs+离线)

    Problem Description ztr loves lucky numbers. Everybody knows that positive integers are lucky if the ...

  3. POJ 2676 Sudoku (数独 DFS)

      Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 14368   Accepted: 7102   Special Judg ...

  4. HDU 5676 ztr loves lucky numbers【DFS】

    题目链接; http://acm.hdu.edu.cn/showproblem.php?pid=5676 题意: 由4和7组成的且4和7出现次数相同的数称为幸运数字,给定n,求不大于n的最大幸运数字. ...

  5. codeforces 686C C. Robbers' watch(dfs)

    题目链接: C. Robbers' watch time limit per test 2 seconds memory limit per test 256 megabytes input stan ...

  6. CodeForces 686C-Robbers' watch

    题意: 一个电子手表的示数是7进制的,现在告诉你一天有多少小时和一小时有多少分钟,问你一天里有多少个时刻,这个表上显示的数字各不相同. 分析: 先找出表上有多少位数字,再按位dfs,看最后得到的数是否 ...

  7. 【一天一道LeetCode】#299. Bulls and Cows

    一天一道LeetCode 本系列文章已全部上传至我的github,地址:ZeeCoder's Github 欢迎大家关注我的新浪微博,我的新浪微博 欢迎转载,转载请注明出处 (一)题目 You are ...

  8. 防盗链之URL参数签名

    一.概述 传统的 IP 禁用.referer 防盗链.User-Agent 防盗链.地区访问控制等防盗链措施已经无法完全满足用户要求,所以开发出URL参数签名方式来防盗链 二.实现 Token防盗链是 ...

  9. 防盗链之URL参数签名 总结

    一.概述 传统的 IP 禁用.referer 防盗链.User-Agent 防盗链.地区访问控制等防盗链措施已经无法完全满足用户要求,所以开发出URL参数签名方式来防盗链 二.实现 Token防盗链是 ...

随机推荐

  1. html5--5-6 绘制圆/弧

    html5--5-6 绘制圆/弧 学习要点 掌握arc() 方法创建圆弧/曲线(用于创建圆或部分圆) 矩形的绘制方法 rect(x,y,w,h)创建一个矩形 strokeRect(x,y,w,hx,y ...

  2. codevs 1143 纪念品分组

    1143 纪念品分组 2007年NOIP全国联赛普及组  时间限制: 1 s  空间限制: 128000 KB  题目等级 : 白银 Silver 题解       题目描述 Description ...

  3. ubuntu16.04 ROS安转及RVIZ启动

    1.软件中心配置 首先打开软件和更新对话框,打开后按照下图进行配置(确保你的"restricted", "universe," 和 "multiver ...

  4. weex 安装过程中遇到的坑

    安装 然后 注意: 在weex-toolkit1.0.8版本后添加了npm5规范的npm-shrinkwrap.json用于锁定包依赖,故npm版本<5的用户需要通过npm i npm@late ...

  5. bzoj1941

    KD-tree **了这道题 这个估价函数好鬼畜,把min打成max... 关于min的估价函数非常鬼畜,具体我也不知道为什么. #include<bits/stdc++.h> using ...

  6. Python的中文处理

    一.使用中文字符 在python源码中如果使用了中文字符,运行时会有错误,解决的办法是在源码的开头部分加入字符编码的声明,下面是一个例子: #!/usr/bin/env python # -*- co ...

  7. system(“pause”)和getchar()

    大家都知道system(“PAUSE”)可以让C程序在运行结束之前暂停运行.用system(“PAUSE”)可以解决运行程序一闪而过,看不到输出结果的问题.有程序员会用system(“PAUSE”)只 ...

  8. 读取关联数据(EF Core2.1.1)

    对象-关系映射框架比如EF有三种 方式使用 模型中的导航属性来加载关联数据. 一..Lazy Loading.(关联数据在访问导航属性时被透明的加载,不需要特别的代码,自动的加载) 当一个实体第一次读 ...

  9. TypeScript完全解读(26课时)_12.TypeScript完全解读-高级类型(1)

    12.TypeScript完全解读-高级类型(1) 高级类型中文网的地址:https://typescript.bootcss.com/advanced-types.html 创建新的测试文件 ind ...

  10. PhpStorm插件之CodeGlance

    安装插件 File->Setting->Pluugins   搜索  CodeGlance 如何使用 安装完插件后,RESTART IDE,随便打开一个文件都可看到效果