题意   把一个数替换为这个数相邻数字差组成的数  知道这个数仅仅剩一位数  若最后的一位数是7  则称原来的数为 July Number  给你一个区间  求这个区间中July Number的个数

从7開始DFS  位数多的数总能由位数小的数推出

#include <bits/stdc++.h>
using namespace std;
const int N = 1e6;
int july[N], n;
set<int> ans; int pw[] = {1, 10, 100, 1000, 10000, 100000, 1000000, 10000000, 100000000};
//剩余长度, 当前位要填的数,通过什么数来搜索, 路径
void dfs(int len, int d, int bas, int cur)
{
if(d < 0 || d > 9) return; //要填的数不合法
if(!len)
{
july[n++] = cur * 10 + d;
return;
}
int k = pw[len - 1];
dfs(len - 1, d - bas / k, bas % k, cur * 10 + d);
dfs(len - 1, d + bas / k, bas % k, cur * 10 + d);
} int main()
{
ans.insert(7);
set<int>::iterator it;
for(int l = 2; l < 10; ++l)
{
n = 0;
for(it = ans.begin(); it != ans.end(); ++it)
for(int i = 1; i < 10; ++i)
dfs(l - 1, i, *it, 0);
for(int i = 0; i < n; ++i) ans.insert(july[i]);
//printf("%d\n", ans.size());
} int a, b = n = 0;
for(it = ans.begin(); it != ans.end(); ++it)
july[n++] = *it;
while(~scanf("%d%d", &a, &b))
printf("%d\n", upper_bound(july, july + n, b) - lower_bound(july, july + n, a)); return 0;
}

July Number


Time Limit: 2 Seconds      Memory Limit: 65536 KB


The digital difference of a positive number is constituted by the difference between each two neighboring digits (with the leading zeros omitted). For example the digital difference of
1135 is 022 = 22. The repeated digital difference, or differential root, can be obtained by caculating the digital difference until a single-digit number is reached. A number whose differential root is 7 is also called July Number. Your job is to tell how
many July Numbers are there lying in the given interval [ab].

Input

There are multiple cases. Each case contains two integers a and b. 1 ≤ a ≤ b ≤ 109.

Output

One integer k, the number of July Numbers.

Sample Input

1 10

Sample Output

1


Author: HE, Ningxu

Contest: ZOJ Monthly, November 2010

ZOJ 3436 July Number(DFS)的更多相关文章

  1. [递推+dfs]ZOJ 3436. July Number

    题目大意: 将一个数字的相邻两位的差(的绝对值)组成一个新的数字.不断反复.假设最后得到7,就称这个数为July Number,比方9024 – 922 – 70 – 7. 题目要求1e9范围内给定区 ...

  2. UVA10624 - Super Number(dfs)

    题目:UVA10624 - Super Number(dfs) 题目大意:给你n和m要求找出这种m位数,从第n位到第m位都满足前i位是能够被i整除,假设没有这种数,输出-1.有多个就输出字典序最小的那 ...

  3. 思维+multiset ZOJ Monthly, July 2015 - H Twelves Monkeys

    题目传送门 /* 题意:n个时刻点,m次时光穿梭,告诉的起点和终点,q次询问,每次询问t时刻t之前有多少时刻点是可以通过两种不同的路径到达 思维:对于当前p时间,从现在到未来穿越到过去的是有效的值,排 ...

  4. ZOJ - 3816 Generalized Palindromic Number dfs

    Generalized Palindromic Number Time Limit: 2 Seconds                                     Memory Limi ...

  5. poj 1564 Sum It Up | zoj 1711 | hdu 1548 (dfs + 剪枝 or 判重)

    Sum It Up Time Limit : 2000/1000ms (Java/Other)   Memory Limit : 65536/32768K (Java/Other) Total Sub ...

  6. ZOJ 1008 Gnome Tetravex(DFS)

    Gnome Tetravex Time Limit: 10 Seconds      Memory Limit: 32768 KB Hart is engaged in playing an inte ...

  7. ZOJ 2412 Farm Irrigation(DFS 条件通讯块)

    意甲冠军  两个农田管内可直接连接到壳体  他们将能够共享一个水源   有11种农田  管道的位置高于一定  一个农田矩阵  问至少须要多少水源 DFS的连通块问题  两个相邻农田的管道能够直接连接的 ...

  8. UVA11882-Biggest Number(DFS+最优化剪枝)

    Problem UVA11882-Biggest Number Accept: 177    Submit: 3117Time Limit: 1000 mSec    Memory Limit : 1 ...

  9. LeetCode Letter Combinations of a Phone Number (DFS)

    题意 Given a digit string, return all possible letter combinations that the number could represent. A ...

随机推荐

  1. 【翻译自mos文章】job 不能自己主动执行--这是另外一个mos文章,本文章有13个解决方法

    job 不能自己主动执行--这是另外一个mos文章 參考原文: Jobs Not Executing Automatically (Doc ID 313102.1) 适用于: Oracle Datab ...

  2. OpenVpn的ipp.txt文件

    ipp=ip pool我猜得,呵呵 ipp.txt文件中存放上一次连接时,客户端分配的ip地址. ipp.txt用来保存上次的连接状态的,并不能为客户端设置固定ip地址. 该文件的格式为:用户名,ip ...

  3. 原来的debussy可以在win7的64位系统下运行吗

    可以的,首先下载两个DLL:msvcr71.dll和msvcp71.dll,然后破解一下就可以了. https://zhidao.baidu.com/question/2419893614880017 ...

  4. [k8s]通过svc来访问集群podhttp://api:8080/api/v1/namespaces/default/services/mynginx/proxy/

    以往的套路是,安装完成k8s集群后-->安装dns-->安装ingress以便外面访问(或者映射nodeport方式) 如果你不想做任何关于ingress/nodeport一些操作.想通过 ...

  5. SQL Server 创建约束图解 唯一 主键

    SQLServer中有五种约束,Primary Key约束.Foreign Key约束.Unique约束.Default约束和Check约束,今天使用SQL Server2008来演示下这几种约束的创 ...

  6. python 连接sql server数据库的示例代码

    首先,到http://pymssql.sourceforge.net/下载pymssql模块,必须安装这个模块才可以用python连接mysql 以下是sql server的操作代码,需要注意字符集 ...

  7. python(25):Unicode 转成中文

    代码转换如下: if __name__ == "__main__": data = "\u5c71\u5cb3\u548c\u4e00\u5207\u4e18\u9675 ...

  8. iOS自定义组与组之间的距离以及视图

    iOS自定义组与组之间的距离以及视图 //头视图高度 - (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(N ...

  9. 有趣的switch应用(填入种类,显示响应的价格)

    <!doctype html> <html lang="en"> <head> <meta charset="UTF-8&quo ...

  10. redis使用redis-cli查看所有的keys及清空所有的数据

    redis_home:redis安装路径: cd %redis_home%/src ./redis-cli -h 127.0.0.1   127.0.0.1:6379> keys *   (em ...