这个题我想到要用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. Linux下mplayer源代码安装方法

    http://www.linuxidc.com/Linux/2007-08/6820.htm 1下载安装mplayer需要的各种软件 去这里下载http://www.mplayerhq.hu/MPla ...

  2. android之硬件访问服务框架

    一.硬件接口描述文件aidl 新增\frameworks\base\core\java\android\os\ILedService.aidl 二.mk编译脚本 修改vi frameworks/bas ...

  3. Android开发之BroadcastReceiver

    BroadcastReceiver:广播接收者.用来接收系统或应用中的广播. 在Android系统中,广播体现在方方面面,例如当开机完成后系统会产生一条广播,接收到这条广播就能实现开机启动服务的功能: ...

  4. VMware下LINUX的虚拟机增加磁盘空间

    先关闭虚拟机电源,做如下设置:“ 虚拟机”--“虚拟机设置”--“磁盘”--“扩展” 可以随意添加你需要增到到的磁盘大小(如15Gb,表示磁盘总量,包含原来的磁盘容量); 再重启电源进入系统做如下步骤 ...

  5. JQuery弹出层,实现弹层切换,可显示可隐藏。

    <!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <t ...

  6. (已实现)相似度到大数据查找之Mysql 文章匹配的一些思路与提高查询速度

    需求,最近实现了文章的原创度检测功能,处理思路一是分词之后做搜索引擎匹配飘红,另一方面是量化词组,按文章.段落.句子做数据库查询,功能基本满足实际需求. 接下来,还需要在海量大数据中快速的查找到与一句 ...

  7. jQuery 源码分析 7: sizzle

    jQuery使用的是sizzle这个选择器引擎,这个引擎以其高速著称,其实现十分精妙但是也足够复杂,下面现简单分析一下相关的代码. 在jQuery的部分API接口是直接引用了Sizzle的方法,这些接 ...

  8. ZOJ 1122 Clock(模拟)

    Clock Time Limit: 2 Seconds      Memory Limit: 65536 KB You are given a standard 12-hour clock with ...

  9. eNSP

    L2交换机 sysvlan 200q interface Vlanif 200ip address 192.168.0.1 24dis thisq interface Ethernet 0/0/1po ...

  10. C++中使用多线程

    使用的函数是CreateThread和CloseHandle相互配合. 举个简单的例子: 申明类变量 HANDLE hThread; DWORD ThreadID; 在需要创建线程的地方使用: hTh ...