题目链接
http://codeforces.com/contest/535/problem/B
题目大意
一个数为幸运数,当且仅当它的每一位要么是4,要么是7
求小于等于
n
的幸运数个数
思路
水题。
由于
注意有个坑点,就是要开long long int,因为可能DFS时算到
PS:其实是我想做div1的B题,结果脑抽点到了div2的B,然后稀里糊涂地秒掉后还纳闷为啥div1的题目这么水。。。
代码
#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <algorithm>
using namespace std;
int ans=0;
long long int n;
void DFS(long long int num)
{
if(num>1e9) return;
if(num<=n) ans++;
DFS(num*10+4);
DFS(num*10+7);
}
int main()
{
scanf("%I64d",&n);
DFS(4);
DFS(7);
printf("%d\n",ans);
return 0;
}