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

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

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

發(fā)布時(shí)間:2023/12/15 编程问答 42 豆豆
生活随笔 收集整理的這篇文章主要介紹了 D - Undoubtedly Lucky Numbers CodeForces - 244B(数论 ) 小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.

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 n are 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.

給一個(gè)數(shù)n,求小于n但是數(shù)位相差不能超過二的數(shù)字。既然不能超過2,就兩邊循環(huán)。再加上dfs就可以跑出來了。
代碼如下:

#include<iostream> #include<cstdio> #include<cstring> #include<cmath> #include<algorithm> #include<set> #define ll long long using namespace std;ll n; set<ll> s;//定義一個(gè)集合,就可以快速去重void dfs(int x,int y,ll ans) {s.insert(ans);ll tx=10*ans+x;ll ty=10*ans+y;if(tx&&tx<=n)//0除外dfs(x,y,tx);if(ty&&ty<=n)dfs(x,y,ty); } int main() {while(scanf("%I64d",&n)!=EOF){s.clear();for(int i=0;i<=9;i++)for(int j=0;j<=9;j++){dfs(i,j,0);}printf("%lld\n",s.size()-1);//n除外} }

努力加油a啊,(o)/~

總結(jié)

以上是生活随笔為你收集整理的D - Undoubtedly Lucky Numbers CodeForces - 244B(数论 )的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。