• LuoGu P4391 [BOI2009]Radio Transmission 无线传输


    P4391 [BOI2009]Radio Transmission 无线传输
    这算是一点(next)数组的妙用吧...题目要求最小循环节(不要求恰好重复完成).先说结论,答案是(n-next_n),为什么呢?
    根据(next)数组的定义,我们可以知道对于(i),(1)(next_i)(next_{i-next_i+1})(i)是相同的,并且并不存在更大的(next)值满足这个条件.
    所以:当(i-next_i)能整除(i)时,(1~i-next_i)就是最小循环节.因为这个题目不要求恰好重复完成,所以不需要判断整除,直接输出即可.
    (Code:)

    #include <algorithm>
    #include <iostream>
    #include <cstdlib>
    #include <cstring>
    #include <cstdio>
    #include <string>
    #include <vector>
    #include <queue>
    #include <cmath>
    #include <ctime>
    #include <map>
    #include <set>
    #define MEM(x,y) memset ( x , y , sizeof ( x ) )
    #define rep(i,a,b) for (int i = a ; i <= b ; ++ i)
    #define per(i,a,b) for (int i = a ; i >= b ; -- i)
    #define pii pair < int , int >
    #define X first
    #define Y second
    #define rint read<int>
    #define int long long
    #define pb push_back
    
    using std::set ;
    using std::pair ;
    using std::max ;
    using std::min ;
    using std::priority_queue ;
    using std::vector ;
    using std::swap ;
    using std::sort ;
    using std::unique ;
    using std::greater ;
    
    template < class T >
        inline T read () {
            T x = 0 , f = 1 ; char ch = getchar () ;
            while ( ch < '0' || ch > '9' ) {
                if ( ch == '-' ) f = - 1 ;
                ch = getchar () ;
            }
           while ( ch >= '0' && ch <= '9' ) {
                x = ( x << 3 ) + ( x << 1 ) + ( ch - 48 ) ;
                ch = getchar () ;
           }
       return f * x ;
    }
    
    template < class T >
        inline void write (T x) {
           static T stk[100] , top = 0 ;
           if ( x == 0 ) { putchar ('0') ; return ; }
           if ( x < 0 ) { x = - x ; putchar ( '-' ) ; }
           while ( x ) { stk[++top] = x % 10 ; x /= 10 ; }
           while ( top ) { putchar ( stk[top--] + '0' ) ; }
           putchar ('
    ') ;
        }
    
    const int N = 1e6 + 100 ;
    
    int n , nxt[N] ;
    char s[N] ;
    
    signed main (int argc , char * argv[]) {
        n = rint () ; scanf ("%s" , s + 1 ) ;
        int j = 0 ; rep ( i , 2 , n ) {
            while ( j && s[i] != s[j+1] ) j = nxt[j] ;
            if ( s[i] == s[j+1] ) ++ j ; nxt[i] = j ;
        }
        printf ("%lld
    " , n - nxt[n] ) ;
        system ("pause") ; return 0 ;
    }
    
    May you return with a young heart after years of fighting.
  • 相关阅读:
    android问题及其解决-优化listView卡顿和怎样禁用ListView的fling
    平安科技移动开发二队技术周报(第三期)
    机房重构(个人版)——类图
    php-wamp环境搭建
    ajax 通过return 返回data值
    cocos2d-x中六种持续性动作
    Android SimpleAdapter
    jquery 判断当前上传文件大小限制上传格式 搭配thinkphp实现上传即预览(模拟异步上传)
    【转】我的第一个Python小程序
    python官网
  • 原文地址:https://www.cnblogs.com/Equinox-Flower/p/11480929.html
Copyright © 2020-2023  润新知