博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
ZOJ 3436 July Number(DFS)
阅读量:6882 次
发布时间:2019-06-27

本文共 1980 字,大约阅读时间需要 6 分钟。

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

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

#include 
using namespace std;const int N = 1e6;int july[N], n;set
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
::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

转载地址:http://ufnbl.baihongyu.com/

你可能感兴趣的文章
从CAP理论中分析Eureka与zookeeper的区别
查看>>
20172318 2018-2019-1 《程序设计与数据结构》第2周学习总结
查看>>
文件操作
查看>>
ubuntu忘记root密码解决
查看>>
windows 80端口被占用的解决方法
查看>>
Qt学习五 - 对话框
查看>>
Android 学习 笔记_12. Spinner的简单实使用
查看>>
手册与参考链接
查看>>
做错的题目——this的指向
查看>>
Struts、JSTL标签库的基本使用方法
查看>>
A Tour of Go Numeric Constants
查看>>
android获取硬件信息
查看>>
计算机操作系统的因果
查看>>
C#中int,string,char[],char的转换(待续)
查看>>
wamp环境的安装
查看>>
BZOJ 4025: 二分图
查看>>
使用百度地图实现详细地址自动补全(补全bug''事件只能绑定到一个上的问题')...
查看>>
Emoji表情处理工具类
查看>>
刚刚考过dev401,出去玩了!有时间我把题目给大家贴出来。
查看>>
不等式解法训练题
查看>>