zoukankan      html  css  js  c++  java
  • UVA1328 Period & SP263 PERIOD

    UVA1328 Period
    对于每一个前缀(i),(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 ;
    }
    
    const int N = 1e6 + 100 ;
    
    int n , nxt[N] , T , cnt ;
    char s[N] ;
    
    signed main (int argc , char * argv[]) {
        T = rint () ;
        while ( T -- ) {
            n = rint () ; if ( ! n ) break ;
            printf ("Test case #%lld
    " , ++ cnt ) ;
            MEM ( nxt , 0 ) ; 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 ;
            }
            rep ( i , 2 , n ) {
                int j = nxt[i] ; if ( i % ( i - j ) ) continue ;
                if ( j ) printf ("%lld %lld
    " , i , i / ( i - j ) ) ;
            }
            putchar(10);
        }
        system ("pause") ; return 0 ;
    }
    

    SP263 PERIOD - Period
    双倍经验,除了输入一模一样.

    May you return with a young heart after years of fighting.
  • 相关阅读:
    MySQL数据库的安装与配置
    java中的反射机制
    详谈设计模式之单列模式
    servlet内部转发与重定向
    servlet基础语句总结
    Servlet映射的俩种方法以及优缺点
    eclipse和idea的快捷键比较及idea如何调节eclipse的快捷键
    servlet
    JDK下载与安装教程
    正则表达式查询
  • 原文地址:https://www.cnblogs.com/Equinox-Flower/p/11480955.html
Copyright © 2011-2022 走看看