UVa - 11452 - Dancing the Cheeky-Cheeky
先上题目:
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:
- The breikin-brokin.
- The meneito.
- The roboqueitor.
- 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的更多相关文章
- Uva 11198 - Dancing Digits
Problem D Dancing Digits 题目链接:http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid ...
- UVA 1291 十四 Dance Dance Revolution
Dance Dance Revolution Time Limit:3000MS Memory Limit:0KB 64bit IO Format:%lld & %llu Su ...
- 【暑假】[深入动态规划]UVa 10618 Tango Tango Insurrection
UVa 10618 Tango Tango Insurrection 题目: Problem A: Tango Tango Insurrection You are attempting to lea ...
- Dancing Links and Exact Cover
1. Exact Cover Problem DLX是用来解决精确覆盖问题行之有效的算法. 在讲解DLX之前,我们先了解一下什么是精确覆盖问题(Exact Cover Problem)? 1.1 Po ...
- 跳跃的舞者,舞蹈链(Dancing Links)算法——求解精确覆盖问题
精确覆盖问题的定义:给定一个由0-1组成的矩阵,是否能找到一个行的集合,使得集合中每一列都恰好包含一个1 例如:如下的矩阵 就包含了这样一个集合(第1.4.5行) 如何利用给定的矩阵求出相应的行的集合 ...
- uva 1354 Mobile Computing ——yhx
aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAABGcAAANuCAYAAAC7f2QuAAAgAElEQVR4nOy9XUhjWbo3vu72RRgkF5
- UVA 10564 Paths through the Hourglass[DP 打印]
UVA - 10564 Paths through the Hourglass 题意: 要求从第一层走到最下面一层,只能往左下或右下走 问有多少条路径之和刚好等于S? 如果有的话,输出字典序最小的路径 ...
- UVA 11404 Palindromic Subsequence[DP LCS 打印]
UVA - 11404 Palindromic Subsequence 题意:一个字符串,删去0个或多个字符,输出字典序最小且最长的回文字符串 不要求路径区间DP都可以做 然而要字典序最小 倒过来求L ...
- UVA&&POJ离散概率与数学期望入门练习[4]
POJ3869 Headshot 题意:给出左轮手枪的子弹序列,打了一枪没子弹,要使下一枪也没子弹概率最大应该rotate还是shoot 条件概率,|00|/(|00|+|01|)和|0|/n谁大的问 ...
随机推荐
- JSP-Runoob:Cookie 处理
ylbtech-JSP-Runoob:Cookie 处理 1.返回顶部 1. JSP Cookie 处理 Cookie是存储在客户机的文本文件,它们保存了大量轨迹信息.在servlet技术基础上,JS ...
- bzoj4082
贪心+倍增 首先如果这个问题在序列上,好像可以按右端点排序,然后从起点开始向能到的最远的地方走. 但是环上不可以,因为随即一个起点可能不是最小的. 然后神思路来了:我们先将环展开倍增,再将区间按右端点 ...
- 图练习-BFS-从起点到目标点的最短步数
http://acm.sdut.edu.cn/sdutoj/problem.php?action=showproblem&problemid=2830 简单bfs #include <s ...
- smarty用法
smarty学习指南 在smarty的模板设计部分我简单的把smarty在模板中的一些常用设置做了简单的介绍,这一节主要来介绍一下如何在smarty中开始我们程序设计.下载Smarty文件放到你们站点 ...
- akka设计模式系列-Backend模式
上一节我们介绍了Akka使用的基本模式,简单点来说就是,发消息给actor,处理结束后返回消息.但这种模式有个缺陷,就是一旦某个消息处理的比较慢,就会阻塞后面所有消息的处理.那么有没有方法规避这种阻塞 ...
- RHEL6.5安装QT5.4,设置环境变量
qt5.4.run在[/home/share]目录下 vim ~/.bashrcexport PATH=/opt/oracle/Qt5.4.1/Tools/QtCreator/bin:/opt/ora ...
- 关于DOM操作的相关案例
1.模态框案例 需求: 打开网页时有一个普通的按钮,点击当前按钮显示一个背景图,中心并弹出一个弹出框,点击X的时候会关闭当前的模态框 代码如下: <!DOCTYPE html> <h ...
- Linux下的文件结构,及对应文件夹的作用
Linux下的文件结构,及对应文件夹的作用 /bin 二进制可执行命令 /dev 设备特殊文件 /etc 系统管理和配置文件 /etc/rc.d 启动的配置文件和脚本 /home 用户主目录的基点,比 ...
- flask web开发日记
from flask import Flask,make_response,redirect,abort app = Flask(__name__) @app.route('/index1') def ...
- PHP 之获取Windows下CPU、内存的使用率
<?php /** * Created by PhpStorm. * User: 25754 * Date: 2019/5/4 * Time: 13:42 */ class SystemInfo ...