水题 不要62 HDU 2089

先预处理出所有的数是不是可能拿来用,我的想法是记录1-i这个区间内可用的数为s[i].

输入a,b.答案就为s[b] - s[a-1].

贴代码:

 1 #include<cstdio>
 2 #define N 1000010
 3 int sum[N];
 4 bool check(int x)
 5 {
 6     while(x)
 7     {
 8         int t = x%10;
 9         if(t == 4) return false;
10         if( t == 2 && (x/10%10) == 6) return false;
11         x /= 10;
12     }
13     return true;
14 }
15 void init()
16 {
17     for(int i=1; i<N-5; ++i)
18     {
19         if(check(i)) sum[i] = sum[i-1]+1;
20         else sum[i] = sum[i-1];
21     }
22 }
23 int main()
24 {
25     //    freopen("in.c","r",stdin);
26     init();
27     int a,b;
28     while(~scanf("%d%d",&a,&b))
29     {
30         if(a==0 && b==0) break;
31         printf("%d
",sum[b]-sum[a-1]);
32     }
33     return 0;
34 }
View Code
原文地址:https://www.cnblogs.com/allh123/p/3265131.html