Uva 12012 Detection of Extraterrestrial 解题报告
2013-05-18 21:56
399 查看
题意:子串循环k次能构成的新的子串长度最长是多少
解法:枚举后缀,找出next数组,再枚举每个后缀的前缀,找出循环节
解法:枚举后缀,找出next数组,再枚举每个后缀的前缀,找出循环节
#include <iostream> #include <cstdio> #include <cstdlib> #include <cstring> #include <algorithm> using namespace std; #define maxn 1005 int n; char st[maxn], s[maxn]; int next[maxn], ans[maxn]; void getnext() { int i=0, j=-1; next[0]=-1; int l=strlen(st); while (i<l) { if (j==-1||st[i]==st[j]) i++, j++, next[i]=j; else j=next[j]; } } int main() { int cas, t=0; scanf("%d", &cas); while (cas--) { scanf("%s", s); int n=strlen(s); memset(ans, 0, sizeof(ans)); for (int i=0; i<n; i++) { for (int j=i; j<n; j++) st[j-i]=s[j]; st[n-i]='\0'; getnext(); for (int j=1; j<=n-i; j++) if (next[j] && j%(j-next[j])==0) { int tt=j/(j-next[j]); for (int k=1; k<=tt; k++) if (tt%k==0) ans[k]=max(ans[k], j); else ans[k]=max(ans[k], (j-next[j])*k); } } ans[1]=n; printf("Case #%d:", ++t); for (int i=1; i<=n; i++) printf(" %d", ans[i]); printf("\n"); } return 0; }
相关文章推荐
- UVA 10010 解题报告
- Uva 10791 - Minimum Sum LCM 解题报告(因式分解)
- UVa 120 - Stacks of Flapjacks 解题报告(暴力)
- UVa 434 - Matty's Blocks 解题报告(水题)
- UVa 669 - Defragment 解题报告(暴力)
- UVa 769 - Magic of David Copperfield 解题报告(思维)
- UVA 539 - The Settlers of Catan 解题报告
- UVA 12538 Version Controlled IDE 解题报告
- UVa 1595 解题报告
- 【解题报告】uva674_Coin Change(硬币找零, dp, 完全背包)
- UVA11059解题报告
- UVALive 5790 Ball Stacking 解题报告
- Uva 120 Stacks of Flapjacks 解题报告
- UVA409 Excuses, Excuses!解题报告
- 2018.2.28【 UVa - 202 】解题报告(紫书练习题,循环小数,输出格式)
- UVa-340 - Master-Mind Hints解题报告
- UVa 755 487--3279解题报告
- uva 489.Hangman Judge 解题报告
- UVa 1344 Tian Ji -- The Horse Racing 解题报告(贪心)
- UVa 1451 Average 解题报告(斜率优化)