ZOJ3436 July Number 【DFS】
来源:互联网 发布:python http接口 编辑:程序博客网 时间:2024/06/10 09:58
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 [a,b].
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
题意:(1)题意:一个数,前后两个数之差组成新数,一直下去,如果结果是7,则为7月数。如7 18 29 70 81 92 108 118 188 198 209 219 229 299 700770 780 790 801 811 881 891 902 910 912 922 980 992
这些都是7月数。给一个区间,问这个区间中有几个7月数。
#include<cstring>#include<iostream>#include<cstdio>#include<algorithm>#include<vector>using namespace std;vector<int> ans,v;int p[11]={0,1,10,100,1000,10000,100000,1000000,10000000,100000000};void dfs(int len,int i,int x,int cut){ cut=cut*10+i; if(len==0) { v.push_back(cut); return ; } int tem=x/p[len]; x=x-tem*p[len]; if(i+tem<=9)dfs(len-1,i+tem,x,cut); if(i-tem>=0)dfs(len-1,i-tem,x,cut);}void slove(){ ans.push_back(7); for(int len=1;len<9;len++) { v.clear(); for(int i=1;i<=9;i++) { for(int j=0;j<ans.size();j++) {//cout<<" ***"; dfs(len,i,ans[j],0); } } ans.insert(ans.end(),v.begin(),v.end()); sort(ans.begin(),ans.end()); ans.erase(unique(ans.begin(),ans.end()),ans.end()); }}int main(){ slove(); int x,y; while(scanf("%d%d",&x,&y)!=EOF) { printf("%d\n",upper_bound(ans.begin(),ans.end(),y)-lower_bound(ans.begin(),ans.end(),x)); } return 0;}
阅读全文
0 0
- ZOJ3436 July Number 【DFS】
- ZOJ3436 July Number
- July Number zoj3436
- ZOJ 3436 July Number(DFS)
- [递推+dfs]ZOJ 3436. July Number
- DFS number
- ZOJ Problem Set - 3436 July Number
- ZOJ3886 2015July月赛 F-Nico Number(线段树)
- July 17th 模拟赛C T2 Number Solution
- UVA10624 - Super Number(dfs)
- DFS---Number of Islands
- uva 10642 Super Number(dfs)
- sdibt 2406 Greatest Number (dfs)
- HDU 5179 - beautiful number (DFS)
- LeetCode Number of Islands DFS
- uva11882Biggest Number(DFS + 剪枝)
- NBUT [1464] Biggest Number dfs
- 【DFS】Letter Combinations of a Phone Number
- 内部类的理解
- 八叉树及K-D树的应用和实现
- Date --String--Timestamp之间的转换
- Fragment
- Machine Learning In Action
- ZOJ3436 July Number 【DFS】
- HDU1301 Jungle Roads
- JAVA总结
- JAVA Instanceof 用法
- 37. Sudoku Solver
- Thread
- 事物—事物的传播性与Spring事物传播特性
- 简单明了的 NLPIR汉语分词系统 搭建流程
- HTML面试题及答案