BZOJ-1026: [SCOI2009]windy数(数位统计

作者: AmadeusChan | 来源:发表于2018-11-19 18:23 被阅读1次

题目:http://www.lydsy.com/JudgeOnline/problem.php?id=1026

裸的数位统计,不过还是很恶心额。。不使劲对拍的话死活A不了555

代码:

#include <cstdio>
#include <algorithm>
#include <cstring>
 
using namespace std ;
 
#define rep( i , x ) for ( ll i = 0 ; i < x ; ++ i )
#define maxn 20
 
typedef long long ll ;
 
ll f[ maxn ][ 10 ] , pre[ maxn ][ 10 ] , cnt , ans ;
 
ll N[ maxn ] , a , b ; 
 
void dfs( ll now ) {
    if ( ! now ) {
        rep( i , N[ now ] + 1 ) pre[ now ][ i ] = 1 ;
        return ; 
    }
    rep( i , N[ now ] ) {
        rep( j , 10 ) if ( abs( i - j ) >= 2 ) {
            pre[ now ][ i ] += f[ now - 1 ][ j ] ;
        }
    }
    dfs( now - 1 ) ;
    rep( i , 10 ) if ( abs( N[ now ] - i ) >= 2 ) {
        pre[ now ][ N[ now ] ] += pre[ now - 1 ][ i ] ;
    }
}
 
void cal( ll x ) {
    if ( ! x ) {
        cnt = 0 ; 
        return ;
    }
    ll len = 0 ; 
    for ( ; x ; x /= 10 ) N[ len ++ ] = x % 10 ;
    if ( len == 1 ) {
        cnt = N[ 0 ] + 1 ; return ; 
    }
    memset( f , 0 , sizeof( f ) ) ;
    rep( i , len ) {
        if ( ! i ) {
            rep( j , 10 ) f[ i ][ j ] = 1 ; 
        } else {
            rep( j , 10 ) rep( k , 10 ) if ( abs( j - k ) >= 2 ) {
                f[ i ][ j ] += f[ i - 1 ][ k ] ;
            }
        }
    }
    memset( pre , 0 , sizeof( pre ) ) ;
    dfs( len - 1 ) ;
    cnt = 0 ;
    rep( i , 10 ) if ( i ) cnt += pre[ len - 1 ][ i ] ;
    rep( i , len - 1 ) rep( j , 9 ) cnt += f[ i ][ j + 1 ] ;
}
 
int main(  ) {
    scanf( "%lld%lld" , &a , &b ) ;
    cal( b ) ;
    ans = cnt ;
    cal( a - 1 ) ;
    printf( "%lld\n" , ans - cnt ) ;
    return 0 ;
}

相关文章

  • BZOJ-1026: [SCOI2009]windy数(数位统计

    题目:http://www.lydsy.com/JudgeOnline/problem.php?id=1026 裸...

  • 328 odd even linked list

    把奇数位的数依次放入一个链表,偶数位的数放入另外一个链表,然后奇数位链表的末尾指向偶数位的链表,同时把偶数位的链表...

  • PTA 7-1 多二了一点 (15 分)

    题目 若一个正整数有 2n 个数位,后 n 个数位组成的数恰好比前 n 个数位组成的数多 2,则称这个数字“多二了...

  • 计算机数据表示

    摘要: 一、二进制数的表示 n:二进制数整数位数 m:二进制数小数位数 B:二进制数标记 如:10111B.110...

  • nginx日志统计分析的相关常用命令

    查询指定关键词行数 统计PV,UV数 统计所有的PV数 统计当天的PV数 统计指定某一天的PV数 根据访问IP统计...

  • Wind challenge the tree

    A windy day It is a windy day today. The tree downstairs ...

  • life-25

    Today's Friday and windy。 It has been strong windy these ...

  • 位运算之奇偶位的互换

    题目: 输入任意十进制数,输出二进制表示形式, 并将奇数位与邻近偶数位互换并且输出十进制和二进制数。 样例: 输入...

  • leetcode 摆动排序 II python 之不需要排序

    排序的话,就没意思了。不排序的话,有一个思想,就是如果奇数位置,则需要比后面一个数小,偶数位置要比后面一个数大,否...

  • Linux查看某个端口的连接数

    查看哪些IP连接本机 查看TCP连接数2.1 统计80端口连接数 2.2 统计httpd协议连接数 2.3 统计已...

网友评论

    本文标题:BZOJ-1026: [SCOI2009]windy数(数位统计

    本文链接:https://www.haomeiwen.com/subject/utiafqtx.html