UVA 11452 Dancing the Cheeky-Cheeky
Posted albert-biu
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了UVA 11452 Dancing the Cheeky-Cheeky相关的知识,希望对你有一定的参考价值。
UVA 11452 "Dancing the Cheeky-Cheeky"
找循环节那里要从后往前找,以解决112234112234这样的数据
#include <bits/stdc++.h>
using namespace std;
const int maxn = 10000;
char a[maxn];
int pi[maxn];
void getnext(int n)
pi[1] = 0;
for (int i = 2, j = 0; i <= n; i++)
while (j > 0 && a[i] != a[j + 1]) j = pi[j];
if (a[i] == a[j + 1]) j++;
pi[i] = j;
int main()
//freopen("in.txt", "r", stdin);
int _;
scanf("%d", &_);
while (_--)
scanf("%s", a + 1);
int n = strlen(a + 1);
getnext(n);
int len;
for (int i = n; i >= 1; i--)
if (pi[i] != 0 && i % (i - pi[i]) == 0)
len = i - pi[i];
break;
int s = n % len;
int cnt = 0;
for (int i = s + 1; cnt < 8; i++, cnt++)
if (i > len) i = 1;
printf("%c", a[i]);
printf("...\n");
return 0;
以上是关于UVA 11452 Dancing the Cheeky-Cheeky的主要内容,如果未能解决你的问题,请参考以下文章
UVA 811 The Fortified Forest (凸包 + 状态压缩枚举)