【NKOJ 1505】 何老板的考古发现
来源:互联网 发布:手机淘宝店标怎么设置 编辑:程序博客网 时间:2024/04/29 15:12
链接
原题地址
思路
把环展开,变成长度为两倍的链,暴力
代码
#include <iostream>#include <cstdio>#include <cstring>using namespace std;char ch[110][20010];int f[110][10010], g[20010], ok[110];int n, m, cnt;void get_f(){ for(int i = 1; i <= n; i ++){ int p = 0; for(int j = 2; j <= m; j ++){ while(p && ch[i][j] != ch[i][p+1]) p = f[i][p]; if(ch[i][j] == ch[i][p+1]) p ++; f[i][j] = p; } }}bool kmp(int x, int y){ int p = 0; for(int i = 1; i <= 2*m; i ++){ while(p && ch[x][i] != ch[y][p+1]) p = f[y][p]; if(ch[x][i] == ch[y][p+1]) p ++; if(p == m) return true; } return false;}void add_ok(int x){ for(int i = 1; i <= m; i ++) ch[x][i+m] = ch[x][i]; ok[++cnt] = x;}int main(){ scanf("%d%d", &n, &m); for(int i = 1; i <= n; i ++) scanf("%s", ch[i]+1); get_f();add_ok(1); for(int i = 2, is = 1; i <= n; i ++, is = 1){ for(int j = 1; j <= cnt; j ++) if(kmp(ok[j],i) == 1){is = 0;break;} if(is) add_ok(i); } printf("%d", cnt); return 0;}
1 0
- 【NKOJ 1505】 何老板的考古发现
- NKOJ 高考假期思维赛 Round2(Div.1) A 何老板快递
- 【计算机历史的考古】
- [转]考古发现两千年前牛肉
- 田野考古绪论之二:田野考古的野外工作方式
- 田野考古绪论之四:我国田野考古的简史
- 竟然如此先进!考古惊现秦始皇的“铁路”
- 科技考古: SPAM 垃圾邮件的起源
- Unix考古记:一个“遗失”的shell
- Unix考古记:一个“遗失”的shell
- Unix考古记:一个“遗失”的shell
- 田野考古地层学之一:地层学的概念
- Unix考古记:一个“遗失”的shell
- 3015年度重大考古发现:中国古代村落“中关村”发现保存完好程序员墓
- 2016.4 半期 射箭馆,爱打怪兽的何老板-----KMP
- 职场中老板因何瞧不上你
- NKOI 1090 何老板捡钻石
- 田野考古绪论之三:田野考古工作的四个阶段
- 本地yum源
- spark和elasticsearch的整合
- 设计模式C++实现(8)——代理模式
- iOS打包ipa给客户测试流程
- java JDBC数据库连接封装和实例代码
- 【NKOJ 1505】 何老板的考古发现
- 设计模式C++实现(9)——享元模式
- 《AngularJS高级程序设计》之分页实现
- 使用angularjs的键盘事件来增强用户体验
- 设计模式C++实现(10)——桥接模式
- LeetCode笔记:110. Balanced Binary Tree
- 网页导航条布局
- Centos7.1 命令行与图形化界面登陆
- 堆和栈的区别(非常经典)