这个题我想到要用kmp找到循环节;

但是后面的我就不会做了;

看到题解才知道是字符串的最小表示;

#include<cstdio>
#include<cstring>
#include<algorithm>
#define maxn 100005
using namespace std; char s[maxn*];
int next[maxn]; void kmp(int n)
{
int j=;
for(int i=;i<=n;i++)
{
while(j>&&s[i]!=s[j+])j=next[j];
if(s[i]==s[j+])++j;
next[i]=j;
}
} void MinimumRepresentation(int n)
{
int i=,j=,k=;
while()
{
if(i==j)j++;
else if(s[j]=='')j++;
else if(s[i]=='')i++;
else if(s[i+k]==s[j+k])k++;
else if(s[i+k]<s[j+k])
{
if(s[i+k]=='')j=j+k;
else j=j+k+;
k=;
}
else
{
if(s[j+k]=='')i=i+k;
else i=i+k+;
k=;
}
if(i>n||j>n||k>=n) break;
}
int t=i<=n?i:j;
for(int i=t;i<t+n;i++)
putchar(s[i]);
puts("");
} int main()
{
//freopen("test0.in","r",stdin);
int t,n;
scanf("%d",&t);
while(t--)
{
scanf("%s",s+);
n=strlen(s+);
bool flag=;
for(int i=;i<=n;i++)
if(s[i]!='')flag=;
if(flag==){printf("1%s\n",s+);continue;}
kmp(n);
int m=n-next[n];
for(int i=m+;i<=(*m);i++)
s[i]=s[i-m];
MinimumRepresentation(m);
}
return ;
}

csuoj 1353: Guessing the Number的更多相关文章

  1. [coj 1353 Guessing the Number]kmp,字符串最小表示法

    题意:给一个字符串,求它的最小子串,使得原串是通过它重复得到的字符串的一个子串. 思路:先求最小长度,最小循环长度可以利用kmp的next数组快速得到,求出长度后然后利用字符串最小表示法求循环节的最小 ...

  2. csuoj 1392: Number Trick

    http://acm.csu.edu.cn/OnlineJudge/problem.php?id=1392 1392: Number Trick Time Limit: 1 Sec  Memory L ...

  3. CSUOJ 1299 - Number Transformation II 打表预处理水DP

    http://122.207.68.93/OnlineJudge/problem.php?id=1299 第二个样例解释.. 3 6 3->4->6..两步.. 由此可以BFS也可以DP. ...

  4. Leetcode: Guess Number Higher or Lower II

    e are playing the Guess Game. The game is as follows: I pick a number from 1 to n. You have to guess ...

  5. Codeforces Gym 100015G Guessing Game 差分约束

    Guessing Game 题目连接: http://codeforces.com/gym/100015/attachments Description Jaehyun has two lists o ...

  6. Palindromic Number (还是大数)

    A number that will be the same when it is written forwards or backwards is known as a Palindromic Nu ...

  7. [USACO 08JAN]Haybale Guessing

    Description The cows, who always have an inferiority complex about their intelligence, have a new gu ...

  8. [USACO08JAN]haybale猜测Haybale Guessing

    题目描述 The cows, who always have an inferiority complex about their intelligence, have a new guessing ...

  9. PAT A1024 Palindromic Number (25 分)——回文,大整数

    A number that will be the same when it is written forwards or backwards is known as a Palindromic Nu ...

随机推荐

  1. 比较两个序列字典序(lexicographicallySmaller)

    bool lexicographicalSmaller(vector<int> a, vector<int> b) { int n = a.size(); int m = b. ...

  2. Linux服务器命令行模式安装Matlab2014a

    Linux服务器命令行模式安装Matlab2014a,有需要的朋友可以参考下. 0.下载安装包 下载Matlab2014a for Linux安装包的ISO镜像文件(感谢万能的度娘)以及破解包(下载地 ...

  3. jquery checkbox全选,全不选,反选方法,jquery checkbox全选只能操作一次

    jquery checkbox全选,全不选,反选方法, jquery checkbox全选只能操作一次, jquery checkbox全选只有第一次成功 >>>>>&g ...

  4. vagrant Ubuntu server 12.04 dpkg: dependency problems prevent configuration of python-gi

    Ubuntu server 12.04因为尝试安装过xfce,导致sudo apt-get install xxx 都会返回,如: vagrant@precise32:~$ sudo apt-get ...

  5. Python(2.7.6) glob - 匹配指定模式的文件

    Python 标准库的 glob 模块支持查询匹配指定模式的文件或目录.这里的模式使用的并不是正则表达式,而是通过通配符来匹配的 Unix 风格的路径名扩展. 支持的通配符: 通配符 说明 *  匹配 ...

  6. linux字符设备驱动学习笔记(一):简单的字符设备驱动

    最近在鼓捣lnux字符设备驱动,在网上搜集的各种关于linux设备驱动的代码和注释,要么是针对2.4的,要么是错误百出,根本就不能运行成功,真希望大家在发博客的时候能认真核对下代码的正确性,特别是要把 ...

  7. UIButton 未响应原因分析

    1.父视图响应者链被阻断;例如:在 UILabel,UIImageView 控件添加UIButton,因为UILabel(userInteractionEnabled属性值为NO) 阻断了响应者链,所 ...

  8. FlashBuilder启动时一闪而过

    晚上的时候把项目目录直接剪切走了 早晨就打不开了 去workspace看log  .\workspace\.metadata\.log 发现如下代码!MESSAGE Could not read me ...

  9. linux命令行下命令参数前的一横(-)和两横(--)的区别

    原文转自:http://blog.csdn.net/songjinshi/article/details/6816776 在解释这些区别之前我们先了解一下有关linux的背景知识,这个需要大家先认真看 ...

  10. 建造者模式(Builder Pattern)

    建造者模式:使用多个简单对象一步步构建成一个复杂的对象. 有时候,我们会创建一个“复杂”的对象,这个对象的由很多子对象构成,由于需求的变化,这个对象的各个部分经常面临剧烈的变化. 继续工厂模式的披萨店 ...