摘要:
http://poj.org/problem?id=2406题意 :求最小的重复子串的个数。思路 :KMP。#include #include #include using namespace std ;const int maxn = 10000000 ;char ch[maxn] ;int next[maxn] ;int main(){ while(scanf("%s",ch)!=EOF) { if(ch[0] == '.') break ; int len = strlen(ch) ; int i = 0 , j =... 阅读全文
摘要:
http://poj.org/problem?id=1961题意 :给你一个字符串,让你输出到第几个字符时,循环结的个数。思路 :这个题和2409差不多,稍微修改一下,加一个循环就行了,用的也是KMP。#include #include #include using namespace std ;const int maxn = 1000010 ;char ch[maxn] ;int next[maxn] ;int main(){ int n ; int test = 1 ; while(scanf("%d%*c",&n)!=EOF) { if(n == ... 阅读全文
摘要:
http://poj.org/problem?id=2492题意 :就是给你n条虫子,m对关系,每一对关系的双方都是异性的,让你找出有没有是同性恋的。思路 :这个题跟POJ1703其实差不多,也是需要一个数组来存跟父亲节点的关系,需要两个集合来存是否有关系,在最后稍微变一下形就OK了。#include#include#include#includeusing namespace std;int pre[100010];//代表着父亲结点,如果D后边是a b,则pre[b]=a ;int father[100010] ;//代表着这个点和父亲结点的关系,是属于同一类还是不同团伙int m,n ; 阅读全文