HDU 2089 不要62
这题开始采用直接计算的方法,后来发现直接计算果断超时,最后选择打表
#include <stdio.h> int lucky[1000024]; void luck ( )//打表,否则超时 { int i,f; for ( i = 1 ; i < 1000024 ; ++i ) { f = 1;//f为标记 int d[ 20 ]; for ( int j = i,k = 0 ; j ; ++k )//对每一个数进行判断 { d[ k ] = j % 10 ; j = j / 10; if ( d[ k ] == 4 ) f = 0 ; if ( k && ( d[ k ] == 6 ) && ( d[ k - 1 ] == 2 ) ) f = 0; } if ( f ) lucky[ i ] = 1; else lucky[ i ] = 0; } } int cal ( int n, int m ) //统计n到m内的lucky数 { int sum = 0; for ( ; n <= m; ++n ) if ( lucky[ n ] ) ++sum; return sum; } int main ( ) { luck( ); int n,m; while ( scanf ( "%d%d",&n,&m ) == 2 ) { if ( n == 0 && m == 0 ) break; if ( n > m )//确保m大于n { n = n ^ m; m = n ^ m; n = n ^ m; } printf ( "%d\n",cal ( n,m ) ); } return 0; }
本人还是新手 ,转载请注明来自Lvsi‘s home