先上题目:

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. 解决UTF-8方法归纳

    1:通过spring配置过滤器解决 <!-- 配置Spring提供的字符编码过滤器 --> <filter> <filter-name>SpringCharacte ...

  2. hibernate基础学习---hierbnate2级缓存

    1:开启二级缓存sessionFactory需要安装jar包 2:在实体类配置文件添加(配置二级缓存).我的配置文件是Account.hbm.xml <?xml version="1. ...

  3. codevs3327选择数字(单调队列优化)

    3327 选择数字  时间限制: 1 s  空间限制: 256000 KB  题目等级 : 钻石 Diamond     题目描述 Description 给定一行n个非负整数a[1]..a[n].现 ...

  4. poj1988Cute Stacking

    题目大意:有几个stack,初始里面有一个cube.支持两种操作:1.move x y: 将x所在的stack移动到y所在stack的顶部.2.count x:数在x所在stack中,在x之下的cub ...

  5. [Swift通天遁地]四、网络和线程-(5)解析网络请求数据:String(字符串)、Data(二进制数据)和JSON数据

    ★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★➤微信公众号:山青咏芝(shanqingyongzhi)➤博客园地址:山青咏芝(https://www.cnblogs. ...

  6. j建立一个小的servlet小程序

    我们建立一个最简单的servlet程序,这个servelt程序只是单纯的输出helloworld. 步骤如下:如图:在Eclipse中选择新建一个项目,其中选择tomcat project然后点击下一 ...

  7. sikuli--前端自动化操作的神器

    前端自动话操作应用很广泛,从网购秒杀活动实现自动化抢购,到区块链货币高频交易前端脚本编写(非合作交易所不提供api的情况下). 自动化的流派分为2类,一类是对DOM对象进行解析的,这个是主流,但是受特 ...

  8. Unity引擎 UGUI

    Unity UGUI讲解 1.导入UI图片资源 2.设置参数: TextureType(纹理类型) 精灵 2D and UI SpriteMode(精灵模式)  Single(单) multiple( ...

  9. 利用php生成验证码

    <?php /** * php生成验证码 * @param $width 画布宽 * @param $height 画布高 * @param $vcodelen 验证码长度 * @param $ ...

  10. python自动化测试框架(一)

    1.开发环境 名称 版本 系统 windows 7 python版本 2.7.14 IDE pycharm2017 2.大致框架流程 :展示了框架实现的业务流程 3.框架介绍 3.1 ======完善 ...