先上题目:

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. E20170628-hm

    forgery   n. 伪造; 伪造罪; 伪造物; 伪造签字; distribute   vt. 分配,散布; 散发,分发; 把…分类; [电] 配电; contribute to(contribu ...

  2. selenium3 + python - 异常处理截图 screenshot

    一.截图方法 1.get_screenshot_as_file(self, filename) --这个方法是获取当前window的截图,出现IOError时候返回False,截图成功返回True. ...

  3. Java初级进阶中高级工程师必备技能

    很多人学了javase以为自己学的已经很OK了,但是其实javase里边有很多的知识点是你不知道的,不管你找的是哪里的javase的视频,大多数是不会讲这些东西,而这些东西你平时业务又不会主动去接触, ...

  4. BigInteger、BigDecimal类的使用详解

    我们都知道在java里边long算是存储长度比较大的了,但是如果有很大的数我们应该怎么处理呢,不用怕,java还为我们准备了一个BigInteger的类,那么这个类到底能存储多大的数呢,这个一时还真不 ...

  5. javascript中for...in和for...of的区别

    for...of循环是ES6引入的新的语法. for...in遍历拿到的x是键(下标).而for...of遍历拿到的x是值,但在对象中会提示不是一个迭代器报错.例子如下: let x; let a = ...

  6. idea 内测设置

    找到安装目录/bin/idea64.exe.vmoptions文件 下面是默认配置 -Xms128m -Xmx750m -XX:ReservedCodeCacheSize=240m -XX:+UseC ...

  7. $CF1141A Game 23$

    这题很简单啊 可以用\(DFS\)来打 毕竟是 \(2^x*3^y=m 输出x+y啊\) 这是最简单的做法 #include <bits/stdc++.h> using namespace ...

  8. 设置myeclipse的JSP、HTML的页面编码格式

    JSP编码格式: 点击菜单上的window--->preferences 在弹出的对话框中点击MyEclise--->Files and Editors--->JSP, 在Encod ...

  9. [转]HTML5 Day 4: Add Drop Down Menu to ASP.NET MVC HTML5 Template using CSS and jQuery

    本文转自:http://pietschsoft.com/post/2010/11/17/HTML5-Day-4-Add-DropDown-Menu-ASPNET-MVC-HTML5-Template- ...

  10. SQL Sever语言 事务

    事务:保障流程的完整执行保证程序某些程序在运行时同时成功同时失败,保证程序的安全性 begin tran --在流程开始的位置加 --此处写SQL语句 if @@error>0 --ERRORS ...