日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

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

發布時間:2023/12/10 编程问答 36 豆豆
生活随笔 收集整理的這篇文章主要介紹了 【CodeForces - 244B】Undoubtedly Lucky Numbers (dfs打表 + 二分) 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

題干:

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打表 + 二分)的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。