toj 2829 cow counting

一开始想多了,以为应该做个数位dp的,后来想了想也不过100W的数据,直接暴力好像也不慢,于是暴力就过了,还挺快。

 1 #include <iostream>

 2 using namespace std;

 3 

 4 bool judge( int x, int d )

 5 {

 6     while ( x )

 7     {

 8         int r = x % 10;

 9         if ( r == d ) return false;

10         x = x / 10;

11     }

12     return true;

13 }

14 

15 int main ()

16 {

17     int n, d;

18     while ( cin >> n >> d )

19     {

20         int cnt = 1;

21         for ( int i = 1; i <= n; i++ )

22         {

23             while ( !judge( cnt, d ) )

24             {

25                 cnt++;

26             }

27             cnt++;

28         }

29         cout << cnt - 1 << endl;

30     }

31     return 0;

32 }

你可能感兴趣的:(count)