HDU3746 Cyclic Nacklace
题目链接:https://vjudge.net/problem/HDU-3746
知识点: KMP
解题思路:
论如何用 \(Next[]\) 数组求循环节。
AC代码:
#include <bits/stdc++.h> using namespace std;
const int maxn = +;
char inp[maxn];
int Next[maxn];
void init(int plen){
memset(Next,,sizeof(Next));
int i=,j=-;
Next[]=-;
while(i<plen){
if(j==-||inp[i]==inp[j]){
i++,j++;
Next[i]=j;
}
else
j=Next[j];
}
}
int main(){
int T;
scanf("%d",&T);
while(T--){
scanf("%s",inp);
int len=strlen(inp);
init(len);
int tmp=len-Next[len]; //tmp:循环节长度
if(tmp!=len&&len%tmp==) printf("0\n");
else printf("%d\n",tmp-Next[len]%tmp); //%tmp有效地忽略了Next[len]里面的完整的循环节
}
return ;
}
HDU3746 Cyclic Nacklace的更多相关文章
- HDU3746 Cyclic Nacklace —— KMP 最小循环节
题目链接:https://vjudge.net/problem/HDU-3746 Cyclic Nacklace Time Limit: 2000/1000 MS (Java/Others) M ...
- hdu-----(3746)Cyclic Nacklace(kmp)
Cyclic Nacklace Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)T ...
- HDU3746 Cyclic Nacklace 【KMP】
Cyclic Nacklace Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) ...
- hdu3746 Cyclic Nacklace【nxt数组应用】【最小循环节】
Cyclic Nacklace Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)T ...
- hdu3746 Cyclic Nacklace KMP
CC always becomes very depressed at the end of this month, he has checked his credit card yesterday, ...
- kuangbin专题十六 KMP&&扩展KMP HDU3746 Cyclic Nacklace
CC always becomes very depressed at the end of this month, he has checked his credit card yesterday, ...
- HDU-3746 Cyclic Nacklace 字符串匹配 KMP算法 求最小循环节
题目链接:https://cn.vjudge.net/problem/HDU-3746 题意 给一串珠子,我们可以在珠子的最右端或最左端加一些珠子 问做一条包含循环珠子的项链,最少还需要多少珠子 思路 ...
- [KMP求最小循环节][HDU3746][Cyclic Nacklace]
题意 给你个字符串,问在字符串末尾还要添加几个字符,使得字符串循环2次以上. 解法 无论这个串是不是循环串 i-next[i] 都能求出它的最小循环节 代码: /* 思路:kmp+字符串的最小循环节问 ...
- Cyclic Nacklace[HDU3746]
Cyclic Nacklace Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) ...
随机推荐
- 使用Spring Boot搭建你的第一个应用程序
文章目录 依赖配置 main程序配置 MVC配置 安全配置 存储 Web 页面和Controller 异常处理 测试 结论 Spring Boot是Spring平台的约定式的应用框架,使用Spring ...
- javescrip内嵌样式与外联样式怎么做?
对于前端初学者,个人JS样式常用的有两种:内嵌样式 ,外联样式:下面通过一个简单的鼠标点击出现设定的验证数字为例进行演示: 先看下效果: 鼠标点击前效果: 鼠标点击后效果: 图中的这个ojbk是我js ...
- 如何把字符串数组从 Swift 传递给 C
作者:Natasha The Robot,原文链接,原文日期:2016-10-27译者:BigbigChai:校对:walkingway:定稿:CMB Swift 允许我们将原生的字符串直接传递给一个 ...
- PHP 面试题总结
1.获取数组最后一个位置的值 比较常规的是:$arr[count($arr)-1]; 貌似还有一个数组函数end();可以直接获取最后一个元素的值.相应的还有reset(),next(),curren ...
- STL 训练 POJ - 1862 Stripies
Description Our chemical biologists have invented a new very useful form of life called stripies (in ...
- bzoj 4152[AMPPZ2014]The Captain
bzoj 4152[AMPPZ2014]The Captain 给定平面上的n个点,定义(x1,y1)到(x2,y2)的费用为min(|x1-x2|,|y1-y2|),求从1号点走到n号点的最小费用. ...
- Python(Redis 中 String/List/Hash 类型数据操作)
1.下载 redis 模块 pip install redis 2.redis 数据库两种连接方式 简单连接 decode_responses=True,写入和读取的键值对中的 value 为 str ...
- python(写入 excel 操作 xlwt 模块)
一.安装 xlwt 模块 pip install xlwt 二.excel 写入操作 这种方式只能新增或者覆盖文件写入 import xlwt # 创建一个workbook 设置编码 workbook ...
- python——random.sample()的用法
写脚本过程中用到了需要随机一段字符串的操作,查了一下资料,对于random.sample的用法,多用于截取列表的指定长度的随机数,但是不会改变列表本身的排序: list = [0,1,2,3,4] r ...
- 用Redislive监控redis
注意:RedisLive是使用Python2.x编写,建议使用2.7,本次环境为Centos 7.2,默认Python版本2.7. 项目地址:https://github.com/nkrode/Red ...