zoukankan      html  css  js  c++  java
  • hdu3476Cyclic Nacklace

    点击打开链接




    // File Name: hdu3746.cpp
    // Author: bo_jwolf
    // Created Time: 2013年05月04日 星期六 19:54:29
    
    #include<vector>
    #include<list>
    #include<map>
    #include<set>
    #include<deque>
    #include<stack>
    #include<bitset>
    #include<algorithm>
    #include<functional>
    #include<numeric>
    #include<utility>
    #include<sstream>
    #include<iostream>
    #include<iomanip>
    #include<cstdio>
    #include<cmath>
    #include<cstdlib>
    #include<cstring>
    #include<ctime>
    
    using namespace std;
    const int maxn = 100010 ;
    char str[ maxn ] ;
    int next[ maxn ] ;
    void getnext( char *p )
    {
    	int j  , k ;
    	j = 0 , k = -1 ;
    	int len = strlen( p ) ;
    	next[ 0 ] = -1 ;
    	while( j < len )
    	{
    		if( k == -1 || p[ j ] == p[ k ] )
    		{
    			j++ ;
    			k++ ;
    			next[ j ] = k ;
    		}
    		else
    			k = next[ k ] ;
    	}
    }
    
    
    int main()
    {
    	int Case ;
    	scanf( "%d" , &Case ) ;
    	while( Case-- )
    	{
    		scanf( "%s" , str ) ;
    		getnext( str );
    		int len = strlen( str ) ;
    
    		if( next[ len ] == 0 )
    		{
    			printf( "%d\n" , len ) ;
    			continue ;
    		}
    		int t = len - next[ len ] ;
    		if( len % t == 0 )
    			printf( "0\n" );
    		else
    			printf( "%d\n" , t - len % t ) ;
    	}
    	return 0;
    }


  • 相关阅读:
    监听事件 队列 邮件发送
    elasticsearch 天气
    elasticsearch
    event 监听事件
    observer 监听的实现 laravel 框架
    中间件
    git 代码 上传到码云
    laravel 省略入口文件 index.php
    limit offset 和limit
    CSS变形和动画
  • 原文地址:https://www.cnblogs.com/javawebsoa/p/3059953.html
Copyright © 2011-2022 走看看