题干:

Polycarpus loves lucky numbers. Everybody knows that lucky numbers are positive integers, whose decimal representation (without leading zeroes) contain only the lucky digits x and y. For example, if x = 4, and y = 7, then numbers 47, 744, 4 are lucky.

Let's call a positive integer a undoubtedly lucky, if there are such digits x and y(0 ≤ x, y ≤ 9), that the decimal representation of number a (without leading zeroes) contains only digits x and y.

Polycarpus has integer n. He wants to know how many positive integers that do not exceed n, are undoubtedly lucky. Help him, count this number.

Input

The first line contains a single integer n (1 ≤ n ≤ 109) — Polycarpus's number.

Output

Print a single integer that says, how many positive integers that do not exceed nare undoubtedly lucky.

Examples

Input

10

Output

10

Input

123

Output

113

Note

In the first test sample all numbers that do not exceed 10 are undoubtedly lucky.

In the second sample numbers 102, 103, 104, 105, 106, 107, 108, 109, 120, 123 are not undoubtedly lucky.

题目大意:

输入一个n,定义Undoubtedly Lucky 数字是仅由小于等于两种数字组成的。问你有多少个 小于等于n的 是Undoubtedly Lucky 的数字。

解题报告:

写法很多啊这题也可以直接用set去重,,,dfs别写萎了就行了。。然后注意这题二分用upper_bound不能用lowerbound。。(因为要分很多种情况,,比如包含这个点或者不包含这个点)

AC代码:

#include<cstdio>
#include<iostream>
#include<algorithm>
#include<queue>
#include<map>
#include<vector>
#include<set>
#include<string>
#include<cmath>
#include<cstring>
#define ll long long
#define pb push_back
#define pm make_pair
#define fi first
#define se second
using namespace std;
const int MAX = 2e5 + 5;
ll up;
int tot;
ll a[MAX*100];
void dfs(ll cur,ll wei,ll i,ll j) {if(wei > 10 /*|| cur > up*/) return ;a[++tot] = cur;
//  if(cur == 101) {
//      putchar('a');
//  }dfs(cur*10+i,wei+1,i,j);dfs(cur*10+j,wei+1,i,j);
}
int main()
{cin>>up;for(int i = 0; i<=9; i++) {for(int j = i+1; j<=9; j++) {dfs(0,0,i,j);}}sort(a+1,a+tot+1);int len = unique(a+1,a+tot+1) - a-1;
//  printf("len = %d\n",len);for(int i = 1; i<=len; i++) printf("%lld ",a[i]);
//  puts("");printf("%d\n",upper_bound(a+1,a+len+1,up) - a - 1 -1);return 0 ;}

总结:

至于为什么main函数的内层for循环为什么要从i+1开始,这是因为我们现在是枚举的那两个数字,这样会保证没有重复啊,不然肯定会多搜一倍的东西。。

【CodeForces - 244B】Undoubtedly Lucky Numbers (dfs打表 + 二分)相关推荐

  1. D - Undoubtedly Lucky Numbers CodeForces - 244B(数论 )

    Polycarpus loves lucky numbers. Everybody knows that lucky numbers are positive integers, whose deci ...

  2. CodeForces - 1547F Array Stabilization (GCD version)(ST表+二分)

    题目链接:点击查看 题目大意:给出一个长度为 nnn 的数组 aaa,下标从 000 开始,每次操作分为两个步骤: 构建出数组 bbb,有 bi=gcd(ai,a(i+1)modn)b_i=gcd(a ...

  3. HDU 5756 ztr loves lucky numbers (dfs)(搜索)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5676 题目大意:只有7和4且7和4数量相等的数字为幸运数字,给你数字n,你要找出大于等于n的最小的幸运 ...

  4. HDU 5676 ztr loves lucky numbers

    -亚信科技,巴卡斯(杭州),壹晨仟阳(杭州),英雄互娱(杭州)  (包括2016级新生)除了校赛,还有什么途径可以申请加入ACM校队?  ztr loves lucky numbers Time Li ...

  5. *【CodeForces - 122D】Lucky Transformation(字符串问题,思维剪枝,优化,有坑,需注意的问题if的层次总结)

    题干: Petya loves lucky numbers. Everybody knows that lucky numbers are positive integers whose decima ...

  6. 【CodeForces - 122B 】Lucky Substring (字符串,水题)

    题干: Petya loves lucky numbers. Everybody knows that lucky numbers are positive integers whose decima ...

  7. *【CodeForces - 122C 】Lucky Sum (bfs记录状态,二分查找,有坑)(或分块)

    题干: Petya loves lucky numbers. Everybody knows that lucky numbers are positive integers whose decima ...

  8. HDU 2563 统计问题 (DFS + 打表)

    统计问题 Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submi ...

  9. Covering(dfs打表+高斯消元+矩阵快速幂)

    传送门 这是个递推题,可以看下维基的各种解释:传送门 假设递推式是一个四元方程,至于为什么也不大清楚(可能是操场是4*n的缘故) 然后得到递推式f(n)=f(n-1)+5*f(n-2)+f(n-3)- ...

最新文章

  1. 苹果手机数据转移到新手机_买了新手机,数据迁移用它轻松搞定
  2. php 获取手机品牌,三到五年内,这家品牌要冲刺手机市场第一梯队
  3. 利用Spring-Boot解析Excel、用Java分析Excel、告别手动输入用程序读取Excel
  4. docker mysql容器 修改时区
  5. 呆呆键盘手11.14号学到的定位-实现滚动门效果
  6. nacos 怎么配置 里的配置ip_Nacos-服务注册地址为内网IP的解决办法
  7. 蛮力算法百元百鸡java_每日一算法:百元百鸡
  8. windows远程访问树莓派方法(+树莓派启动方法)
  9. 一些来自STL的好东西
  10. 27 MM配置-采购-采购申请-定义凭证层的屏幕格式
  11. java 多态 优势
  12. 【干货】腾讯员工职业发展框架.pdf(附下载链接)
  13. 综述!信息检索中的花式预训练
  14. macbook 放flash发烫,转html5
  15. windows10常用快捷键
  16. 信息检索-矩阵理论与线性代数
  17. Ubuntu(debian) 程序 dep 打包
  18. linux deploy安装kali和磁盘扩容
  19. 群晖 android软件,Synology Moments下载-Synology Moments app下载v1.3.2安卓版-西西软件下载...
  20. 咨询报告中常用的英文缩写

热门文章

  1. nlp中的经典深度学习模型(二)
  2. php为什么搜不到字段,php-通过多个字段搜索.有时一个领域,有时不止一个领域
  3. Linux禁止ip拒绝访问80,Linux iptables 设置允许(禁止)IP范围
  4. 回溯求解排列组合(求源码评论区留言)
  5. 解决使用Servlet输出乱码问题(一行代码解决一切)
  6. 甘肃政法学院计算机科学与技术试题,甘肃政法学院计算机科学与技术专业课程教学大纲.doc...
  7. java小白会有那些工作_Java小白找工作与学习的第四天
  8. django 学习 (三) 模板变量
  9. 正在读取软件包列表... 有错误!
  10. 进程控制2--exec族