摘要: 原题链接:http://poj.org/problem?id=2488分析:如果存在合法路径,那么一定可以将路径的起始点定为(A,1),从该点按字典序DFS,如果找到一条路径,那么这条路即为所求。 1 #include 2 #include 3 #include 4 #include 5 #define maxn 27 6 using namespace std; 7 int dirx[8]={-2,-2,-1,-1,1,1,2,2}; 8 int diry[8]={-1,1,-2,2,-2,2,-1,1}; 9 char path[maxn0&&ny>0&&am 阅读全文
posted @ 2013-08-09 19:22 EtheGreat 阅读(222) 评论(0) 推荐(0) 编辑
摘要: 原题链接:http://poj.org/problem?id=2406分析:求最小周期。 1 #include 2 #include 3 #include 4 #include 5 #define maxn 1000005 6 using namespace std; 7 char s[maxn]; 8 int next[maxn],len; 9 void get_next()10 {11 int i=0,j=-1;len=strlen(s);12 next[0]=-1;13 while(i<len)14 {15 if(j==-1||s[i]==... 阅读全文
posted @ 2013-08-09 09:21 EtheGreat 阅读(224) 评论(0) 推荐(0) 编辑
摘要: 原题链接:http://poj.org/problem?id=2752分析:no! 1 #include 2 #include 3 #include 4 #define maxn 400005 5 using namespace std; 6 char s[maxn]; 7 int len,next[maxn],ans[maxn]; 8 void get_next() 9 {10 int i=0,j=-1;len=strlen(s);11 next[0]=-1;12 while(i=1;j--)31 printf("%d ",ans[j]);32 ... 阅读全文
posted @ 2013-08-09 01:09 EtheGreat 阅读(152) 评论(0) 推荐(0) 编辑
摘要: 原题链接:http://poj.org/problem?id=3461分析:求一个串在另一个串中出现的次数,显然用KMP可以解决。 1 #include 2 #include 3 #include 4 #define maxn1 10005 5 #define maxn2 1000005 6 using namespace std; 7 char s[maxn1],t[maxn2]; 8 int next[maxn1],sum,len1,len2; 9 void get_next()10 {11 int i,j;len1=strlen(s);12 next[0]=-1;13 ... 阅读全文
posted @ 2013-08-09 00:21 EtheGreat 阅读(219) 评论(0) 推荐(0) 编辑