Power Strings poj2406(神代码)
Time Limit: 3000MS | Memory Limit: 65536K | |
Total Submissions: 29402 | Accepted: 12296 |
Description
Input
Output
Sample Input
- abcd
- aaaa
- ababab
- .
Sample Output
- 1
- 4
- 3
- 两种做法:
- #include <iostream>
- #include <stdio.h>
- #include <string.h>
- using namespace std;
- char a[];
- int t;
- int main()
- {
- char x;
- while()
- {
- t=;
- x=getchar();
- if(x=='.')break;
- while()
- {
- a[t++]=x;
- if(x=='\n')break;
- x=getchar();
- }
- int p=,k=;
- t--;
- for(int i=; i<t; i++)
- {
- if(a[i]==a[i%p])
- k++;
- else
- {
- if(p==k)k++;
- p=k;
- }
- }
- if(t%p==)
- printf("%d\n",t/p);
- else printf("1\n");
- }
- }
- #include <iostream>
- #include <stdio.h>
- #include <string.h>
- using namespace std;
- char a[];
- int t,next[];
- void fun()
- {
- next[]=;
- int i,j=;
- for(i=;i<t;i++)
- {
- while(j>&&a[i]!=a[j])j=next[j-];
- if(a[i]==a[j])j++;
- next[i]=j;
- }
- }
- int main()
- {
- char x;
- while()
- {
- t=;
- x=getchar();
- if(x=='.')break;
- while()
- {
- a[t++]=x;
- if(x=='\n')break;
- x=getchar();
- }
- t--;
- fun();
- if(t%(t-next[t-])==)
- printf("%d\n",t/(t-next[t-]));
- else printf("1\n");
- }
- }
Power Strings poj2406(神代码)的更多相关文章
- Power Strings[poj2406]题解
Power Strings Description - Given two strings a and b we define ab to be their concatenation. For ex ...
- Power Strings POJ2406 KMP 求最小循环节
相比一般KMP,构建next数组需要多循环一次,因为next[j]代表前j-1个字符的最长相同前缀后缀,比如字符串为aab aab aab共9个字符,则next[10]等于前9个字符中最长相同前缀后缀 ...
- 【POJ2406】 Power Strings (KMP)
Power Strings Description Given two strings a and b we define a*b to be their concatenation. For exa ...
- POJ2406 Power Strings —— KMP or 后缀数组 最小循环节
题目链接:https://vjudge.net/problem/POJ-2406 Power Strings Time Limit: 3000MS Memory Limit: 65536K Tot ...
- poj2406 Power Strings(kmp失配函数)
Power Strings Time Limit: 3000MS Memory Limit: 65536K Total Submissions: 39291 Accepted: 16315 Descr ...
- poj2406 Power Strings(kmp)
poj2406 Power Strings(kmp) 给出一个字符串,问这个字符串是一个字符串重复几次.要求最大化重复次数. 若当前字符串为S,用kmp匹配'\0'+S和S即可. #include & ...
- poj2406 Power Strings (kmp 求最小循环字串)
Power Strings Time Limit: 3000MS Memory Limit: 65536K Total Submissions: 47748 Accepted: 19902 ...
- poj 2406 Power Strings (kmp 中 next 数组的应用||后缀数组)
http://poj.org/problem?id=2406 Power Strings Time Limit: 3000MS Memory Limit: 65536K Total Submiss ...
- poj 2406:Power Strings(KMP算法,next[]数组的理解)
Power Strings Time Limit: 3000MS Memory Limit: 65536K Total Submissions: 30069 Accepted: 12553 D ...
随机推荐
- [2014-02-19]ConfigurationSection:让web.config配置更有条理
本文针对新手 使用Web.config的配置信息,一般都习惯于使用 ConfigurationManager.AppSettings["ConfigKey"] 当程序不断迭代,开发 ...
- live事件的替代方法on的使用注意事项
根据jQuery的官方描述,live方法在1.7中已经不建议使用,在1.9中删除了这个方法.并建议在以后的代码中使用on方法来替代. on方法可以接受三个参数:事件名.触发选择器.事件函数. 需要特别 ...
- .net分布式压力测试工具(Beetle.DT)
肯定有人会问为什么会写这样一个开源工具?和现有的有什么差别?不过对于一个程序员来说写东西还真不需要理由的:),主要原因是工作有点闲(开玩笑),不过说实话一个程员怎可能会停止写代码呢(作为一个奔4的程序 ...
- JSP页面中<%!%>与<%%>与<%=%>
首先,我们要了解jsp运行原理.JSP的本质就是一个Servlet,JSP的运行之前会先被Tomcat服务器翻译为.java文件,然后在将.java文本编译 为.class文件,而我们在访问jsp时, ...
- 递归的二叉查找树Java实现
package practice; public class TestMain { public static void main(String[] args) { int[] ao = {50,18 ...
- LVS之DR模式实战及高可用性
author:JevonWei 版权声明:原创作品 LVS-DR实现同网段调度web模式 拓扑环境 网络环境 RS1 RIP 192.168.198.138/24 VIP 192.168.198.10 ...
- Centos 6修复/boot目录及fstab等系统文件
author:JevonWei 版权声明:原创作品 错误界面 系统修复过程中,若需要修复fatab挂载文件,磁盘分区为lvm逻辑卷格式,则默认在修复模式下处于不可活动状态,需使用vgchage -ay ...
- 【C#多线程编程实战笔记】二、 线程同步
使用Mutex类-互斥锁 owned为true,互斥锁的初始状态就是被主线程所获取,否则处于未获取状态 name为定义的互斥锁名称,在整个操作系统只有一个命名未CSharpThreadingCookb ...
- Project 7:自然数的拆分
自然数的拆分:任何一个大于1的自然数N,总可以拆分成若干个自然数之和,并且有多种拆分方法.例如自然数5,可以有如下一些拆分方法: 5=1+1+1+1+1 5=1+1+1+2 5=1+2+2 5=1+4 ...
- JavaScript二维码生成——qrcode.js
在开发中,有时候,我们需要根据不同的内容来动态生成二维码,则可以使用qrcode.js这个小插件来实现. 1.qrcode.js文件内容: (1)未压缩(qrcode.js): /** * @file ...