先上题目:

F. Dancing the Cheeky-Cheeky 

Context

The Cheeky-Cheeky is a new song. They dance it in Mula, and also in Hong Kong. All the freekies dance it, and the geek all love it. And the Cheeky-Cheeky is danced like this:

  1. The breikin-brokin.
  2. The meneito.
  3. The roboqueitor.
  4. The maiquel-guolkin.

The Problem

In this problem you have to learn to dance the Cheeky-Cheeky. This dancing consists of 4 basic steps (as listed above) that are arranged into a particular sequence. Then this sequence can be repeated an arbitrary number of times.

For example, if the sequence is "123", then the Cheeky-Cheeky is danced like this: "12312312312312...". But if the sequence is "123124", then the steps of the dancing are "123124123124123...".

You are given some of the steps of a particular dancing. Those steps will contain between 2 (inclusive) and 3 (not inclusive) times the basic sequence. You have to continue the dancing.

For example, if the basic sequence is "123", we can have the following possibilities:

Input

Output

123123 12312312...
1231231 23123123...
12312312 31231231...

The Input

The first line of the input contains an integer indicating the number of test cases.

Each case contains some of the first steps of a dancing. It is a single line with a list of digits (1, 2, 3 or 4) with no spaces between them. It will not have more than 2000 steps. Remember that the case contains the basic sequence twice, and possibly has some more steps (but not thrice).

The Output

For each test case, the output should contain the 8 following steps of the dancing, followed by three dots "...".

Sample Input

6
123123
1231231
12312312
123124123124
12312412312412
12312412312412312

Sample Output

12312312...
23123123...
31231231...
12312412...
31241231...
41231241...   题意:给出最多只有4种字符的序列,这个序列前面一定有重复的部分,将这个序列接下来的八位输出。
  用kmp求一次next数组,然后从后往前扫找到循环节的长度,然后就用循环节模一下给出的串,将剩下的部分输出就可以了。 上代码:
 #include <cstdio>
#include <cstring>
#define MAX 2002
using namespace std; char s[MAX];
int l,next[MAX],le; void getnext(){
int k,i;
k=-; i=;
memset(next,-,sizeof(next));
while(i<=l-){
if(k==- || s[i]==s[k]){
k++; i++; next[i]=k;
}else k=next[k];
}
} int main()
{
int t,r;
//freopen("data.txt","r",stdin);
scanf("%d",&t);
while(t--){
scanf("%s",s);
l=strlen(s);
getnext();
for(int i=l;i>=;i--){
if(i%(i-next[i])==){
le=i-next[i]; break;
}
}
r=l%le;
for(int i=;i<;i++){
putchar(s[r]);
r=(r+)%le;
}
printf("...\n");
}
return ;
}

/*UVa 11452*/

												

UVa - 11452 - Dancing the Cheeky-Cheeky的更多相关文章

  1. Uva 11198 - Dancing Digits

    Problem D Dancing Digits 题目链接:http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid ...

  2. UVA 1291 十四 Dance Dance Revolution

    Dance Dance Revolution Time Limit:3000MS     Memory Limit:0KB     64bit IO Format:%lld & %llu Su ...

  3. 【暑假】[深入动态规划]UVa 10618 Tango Tango Insurrection

    UVa 10618 Tango Tango Insurrection 题目: Problem A: Tango Tango Insurrection You are attempting to lea ...

  4. Dancing Links and Exact Cover

    1. Exact Cover Problem DLX是用来解决精确覆盖问题行之有效的算法. 在讲解DLX之前,我们先了解一下什么是精确覆盖问题(Exact Cover Problem)? 1.1 Po ...

  5. 跳跃的舞者,舞蹈链(Dancing Links)算法——求解精确覆盖问题

    精确覆盖问题的定义:给定一个由0-1组成的矩阵,是否能找到一个行的集合,使得集合中每一列都恰好包含一个1 例如:如下的矩阵 就包含了这样一个集合(第1.4.5行) 如何利用给定的矩阵求出相应的行的集合 ...

  6. uva 1354 Mobile Computing ——yhx

    aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAABGcAAANuCAYAAAC7f2QuAAAgAElEQVR4nOy9XUhjWbo3vu72RRgkF5

  7. UVA 10564 Paths through the Hourglass[DP 打印]

    UVA - 10564 Paths through the Hourglass 题意: 要求从第一层走到最下面一层,只能往左下或右下走 问有多少条路径之和刚好等于S? 如果有的话,输出字典序最小的路径 ...

  8. UVA 11404 Palindromic Subsequence[DP LCS 打印]

    UVA - 11404 Palindromic Subsequence 题意:一个字符串,删去0个或多个字符,输出字典序最小且最长的回文字符串 不要求路径区间DP都可以做 然而要字典序最小 倒过来求L ...

  9. UVA&&POJ离散概率与数学期望入门练习[4]

    POJ3869 Headshot 题意:给出左轮手枪的子弹序列,打了一枪没子弹,要使下一枪也没子弹概率最大应该rotate还是shoot 条件概率,|00|/(|00|+|01|)和|0|/n谁大的问 ...

随机推荐

  1. Makefile 实际用例分析(三) ------- 是用GUN automake 处理自己的工程

    前面两篇已经说过了自己怎么去为一个工程写makefile: 第一篇 第二篇 现在这一篇说的是怎么使用GNU的工具去写一个符合开源标准的Makefile呢! 首先我觉你应该参考: Automake Au ...

  2. ref 和out的区别

    在C#语言中,参数的传递有两种,一种是值传递,一种是引用传递.ref与out这两种方式都属于引用传递,只是他们的用法稍有不同.下面看几个例子 使用ref的例子 class test { static ...

  3. hash练习们

    610. 数对的个数 ★★   输入文件:dec.in   输出文件:dec.out   简单对比时间限制:1 s   内存限制:128 MB Description出题是一件痛苦的事情!题目看多了也 ...

  4. Win7 + VS2015 + CMake3.6.1-GUI + Makefile 编译开源库

    CMake生成Unicode版本VC工程 Just add this line in your top CMakeLists.txt file:     add_definitions(-DUNICO ...

  5. ORA-01075: you are currently logged on

    [root@hear01 ~]# su - oracle[oracle@hear01 ~]$ sqlplus "/as sysdba" SQL*Plus: Release 11.2 ...

  6. ACM_小游戏(棋盘博弈)

    Problem Description: 最近kiki无事可做,于是他想玩棋盘游戏.棋盘的大小是n * m.首先,棋子放置在右上角(1,m). 每次可以将棋子向左方,下方或左下方移动一个位置.当移动到 ...

  7. InnoDB锁机制之Gap Lock、Next-Key Lock、Record Lock解析

    InnoDB锁机制之Gap Lock.Next-Key Lock.Record Lock解析 有意思,解释的很好

  8. Linq学习(五)-多表连接

    本将主要介绍 内连接与 外连接 1.join Linq to sql from a in Blog_Users join b in Blog_UserInfo on a.UserId equals b ...

  9. Manacher 学习笔记

    \(\\\) \(Manacher\) 一种常用的字符串算法,用于处理一些回文字符相关的问题. 回文串:从前向后和从后向前输出一致. 回文中心:以这里开始,每次向外左右各扩展一个字符得到的回文串的中心 ...

  10. debounce还是throttle(去抖和节流)

    debounce 去抖 我的理解很简单,比方说window.onscroll会疯狂触发handler,此时给它一个debounce(handler, delayTime). 就是不管你延时时间内触发了 ...