AcWing 5147. 数量
原题链接
中等
作者:
糖醋拐杖_8
,
2024-02-25 20:20:32
,
所有人可见
,
阅读 21
#include <iostream>
#include <cstring>
#include <algorithm>
#include <queue>
using namespace std;
typedef long long LL;
LL n;
LL res;
void bfs(long long u)
{
queue <long long> q;
q.push(u);
while (q.size() )
{
LL t = q.front();
q.pop();
if (t > n) return ;
if (t!= 0 ) res++;
for (int i = 0; i < 2; i ++ )
{
LL a;
if (i == 0) a = t * 10 + 4;
else a = t * 10 + 7;
if (t > n) continue;
q.push(a);
}
}
}
int main()
{
cin >> n;
bfs(0);
cout << res <<endl;
return 0;
}
bfs
#include <iostream>
#include <cstring>
#include <algorithm>
using namespace std;
typedef long long LL;
const int N = 1e9 + 10;
LL n;
LL res;
void dfs(long long u)
{
if (u > n) return;
if (u != 0)res++;
dfs(u * 10 + 4);
dfs(u * 10 + 7);
}
int main()
{
cin >> n;
dfs(0);
cout << res <<endl;
return 0;
}
dfs