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 ;
}

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. Java8初体验(2):Stream语法详解

    原文出处: 一冰_天锦 上篇文章Java8初体验(1):lambda表达式语法比较详细的介绍了lambda表达式的方方面面,细心的读者会发现那篇文章的例子中有很多Stream的例子.这些Stream的 ...

  2. android BLE Peripheral 手机模拟设备发出BLE广播 BluetoothLeAdvertiser

    android 从4.3系统开始可以连接BLE设备,这个大家都知道了.iOS是从7.0版本开始支持BLE. android 进入5.0时代时,开放了一个新功能,手机可以模拟设备发出BLE广播, 这个新 ...

  3. plsql导入cvs 时提示missing right parenthesis

    删除自动生成的时间格式值,如:SQL function框里自动生成的值

  4. C语言system()函数:执行shell命令

    头文件:#include <stdlib.h> 定义函数:int system(const char * string); 函数说明:system()会调用fork()产生子进程, 由子进 ...

  5. JAVA 内部类 (二)

    一.为什么要使用内部类 为什么要使用内部类?在<Think in java>中有这样一句话:使用内部类最吸引人的原因是:每个内部类都能独立地继承一个(接口的)实现,所以无论外围类是否已经继 ...

  6. Linux下的RTC子系统

    转自:http://blog.csdn.net/weiqing1981127/article/details/8484268 实时时钟的作用主要是为操作系统提供一个可靠的时间,并在断电下,RTC时钟也 ...

  7. Throwable相关知识1

    Throwable是所有异常Exception和错误Error的祖先 Throwable是java.lang包中一个专门用来处理异常的类.它有两个子类,即Error 和Exception,它们分别用来 ...

  8. 1.7-1.12 MapReduce Wordflow

    一.案例运行MapReduce Wordflow 1.准备examples [root@hadoop-senior oozie-4.0.0-cdh5.3.6]# pwd /opt/cdh-5.3.6/ ...

  9. POJ - 3414 Pots BFS(著名倒水问题升级版)

    Pots You are given two pots, having the volume of A and B liters respectively. The following operati ...

  10. C#中的explicit和implicit了解一下吧

    今天在研究公司项目框架的时候看到了下面的用法,public static implicit operator JsonData(int data);.貌似很久没用过这种隐式转换的写法了,因此重新温习一 ...