这个题我想到要用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. 【原】Spring与MongoDB集成:配置

    MongoDB的API提供了DBObject接口来实现BSONObject的操作方法,BasicDBObject是具体实现.但是并没有提供DBObject与BeanObject的转换.在还没有了解到与 ...

  2. activity和fragment的声明周期

    Activity生命周期: Fragment生命周期:

  3. Echarts基于动态数据初步使用 及问题 代码记录.

    ECHARTS 插件 基本的动态数据展示(横向图) 下载 echarts.commn.min.js文件 在页面中进行引用, 并为Echarts图形准备一个div盒子 <!-- 引入插件 --&g ...

  4. C#学习笔记3:提示“截断字符串或二进制数据”错误解决方法

    1.调试程序如出现“截断字符串或二进制数据”的关于数据库的错误,可以先试一试修改数据库中字符定义的长度. 2.使用ManualResetEvent前需导入 命名空间System.Threading; ...

  5. 月下载量上千次的APP源码分享

    在360上面上线了一个月,下载量上千余次.这里把代码都分享出来,供大家学习哈!还包括教大家如何接入广告,赚点小钱花花,喜欢的帮忙顶一个,大神见了勿喷,小学僧刚学Android没多久. 首先介绍这款应用 ...

  6. LVS概述

    LVS原理概述: lvs是一个开源软件,是Linux virtual server的简写,即linux虚拟服务器,是一个虚拟的服务器集群系统,lvs集群采用ip负载均衡技术和基于内容的请求分发技术.将 ...

  7. (一)问候Spring4

    第一节:Spring 简介 Spring 作者:Rod Johnson: 官方网站:http://spring.io/ 最新开发包及文档下载地址:http://repo.springsource.or ...

  8. struts2中<s:property>的用法

    1,访问Action值栈中的普通属性: <s:property value="attrName"/> 2,访问Action值栈中的对象属性(要有get set方法):  ...

  9. DOM4J方式解析XML文件

    dom4j介绍 dom4j的项目地址:http://sourceforge.net/projects/dom4j/?source=directory dom4j是一个简单的开源库,用于处理XML. X ...

  10. Json 映射 的使用 及 JS 数组的使用

    Json 映射的使用: var nameMap = { 'A': 'A1', 'B': 'B1', 'B': 'B1' }; var selectedName='A'; if (nameMap[sel ...