找规律

S+1 = S +'L'+~rev(S)

Problem D

Decoding the Hallway

Problem D

Edward is now 21 years old. He has to appear in an exam to renew his State Alchemist

title. This year the exam is arranged in a bit different way. There will be a long hallway. Each

alchemist will enter the hallway from the left side and come out from the right side and he has to

do this n times. During this tour they have to bend the hallway segments right-left alternatively.

Let’s describe the process in some pictures:

• First time (First picture): Initially, the hallway is a straight line (soft line in the first

picture). So alchemist will bend this segment to right side (he is going from left to right)

like the hard line in the first picture above.

• Second time (Second picture): Now he will find two segments in hallway (like soft line in

picture). So he will bend the first hallway to right, second one to left (like the hard lines).

• Third time (Third picture): Now he will find four segments in the hallway (like the soft

lines) and he will bend them to Right, Left, Right and Left respectively.

• And this goes on for fourth and fifth times in the picture.

Since Full Metal Alchemist Edward is so good, he did it perfectly. Now it is turn of the

judges to check the bending if it is correct or not. The judge enters at the left end and comes

out from the right end. But during his travel he notes down the turning, R for Right and L for

Left. So if n = 1, then the judge would have noted down L. If n = 2, it would have been LLR.

For n = 4, it would have been: LLRLLRRLLLRRLRR.

Since this string will grow exponentially with n, it will be tough to check whether the bending

is correct or not. So the judges have some pre-generated strings and they know whether this

string will appear as substring in the final string or not. Unfortunately the judges have lost the

answer sheet, can you help them to recover it?

INPUT

First line of the test file contains a positive integer T denoting number of test cases (T <=

105). Hence follows T lines, each containing an integer and a string: n S. n is the number of

times Edward has passed through the hallway; and S is the string the judge is going to check

with. You may assume that S consists of only the letters L and R. (n <= 1000, length of S

<= 100). Also you may assume that length of S will not be greater than the length of the

string for n.

OUTPUT

For each test case output the case number and Yes or No denoting whether the string is in

the final string as substring.

1Problem D

Decoding the Hallway

SAMPLE INPUT SAMPLE OUTPUT

2

1 R

4 LRRLL Case 1: No

Case 2: Yes

2

Pro

#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <string> using namespace std; string letsgo[20],str; string reverse(string x)
{
string y;
int sz=x.length();
for(int i=sz-1;i>=0;i--)
{
y+=x[i];
}
return y;
} string change(string x)
{
string y;
int sz=x.length();
for(int i=0;i<sz;i++)
{
if(x[i]=='L') y+="R";
else y+="L";
}
return y;
} void init()
{
letsgo[1]="L";
for(int i=2;i<=10;i++)
{
int sz=letsgo[i-1].length();
string rletsgo=reverse(letsgo[i-1]);
rletsgo=change(rletsgo);
letsgo[i]=letsgo[i-1]+"L"+rletsgo;
}
} bool check_left(int L,int R)
{
string text;
for(int i=L;i<=R;i++)
{
text+=str[i];
}
int t=letsgo[10].find(str);
if(t<letsgo[10].length())
return true;
return false;
} bool check_right(int L,int R)
{
string text;
for(int i=L;i<=R;i++)
{
text+=str[i];
}
text=reverse(change(text));
int t=letsgo[10].find(str);
if(t<letsgo[10].length())
return true;
return false;
} int main()
{
init();
int n;
int T_T,cas=1;
cin>>T_T;
while(T_T--)
{
cin>>n>>str;
int len=str.length();
cout<<"Case "<<cas++<<": ";
if(n<=10)
{
int t=letsgo[n].find(str);
if(t<letsgo[n].length())
{
puts("Yes");
}
else
{
puts("No");
}
}
else
{
int m=str.length();
bool flag=false;
for(int i=0;i<m;i++)
{
if(str[i]=='L')
{
if(check_left(0,i-1)&&check_right(i+1,m-1))
{
flag=true;
break;
}
}
}
if(flag==false)
{
int t=letsgo[10].find(str);
if(t<letsgo[10].length())
{
flag=true;
}
}
if(flag) puts("Yes");
else puts("No");
}
}
return 0;
}

SWERC13 Decoding the Hallway的更多相关文章

  1. Block Markov Coding & Decoding

    Block Markov coding在一系列block上进行.在除了第一个和最后一个block上,都发送一个新消息.但是,每个block上发送的码字不仅取决于新的信息,也跟之前的一个或多个block ...

  2. UVA 12897 Decoding Baby Boos 暴力

    Decoding Baby Boos Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.hust.edu.cn/vjudge/contes ...

  3. Base64 Encoding / Decoding in Node.js

    Posted on April 20th, 2012 under Node.js Tags: ASCII, Buffer, Encoding, node.js, UTF So how do you e ...

  4. Codeforces Gym 100002 D"Decoding Task" 数学

    Problem D"Decoding Task" Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com ...

  5. ios Object Encoding and Decoding with NSSecureCoding Protocol

    Object Encoding and Decoding with NSSecureCoding Protocol February 27, 2014 MISC NSCoding is a fanta ...

  6. UVa 213 Message Decoding(World Finals1991,串)

     Message Decoding  Some message encoding schemes require that an encoded message be sent in two part ...

  7. FFmpeg的H.264解码器源代码简单分析:熵解码(Entropy Decoding)部分

    ===================================================== H.264源代码分析文章列表: [编码 - x264] x264源代码简单分析:概述 x26 ...

  8. 论文笔记:Decoders Matter for Semantic Segmentation: Data-Dependent Decoding Enables Flexible Feature Aggregation

    Decoders Matter for Semantic Segmentation: Data-Dependent Decoding Enables Flexible Feature Aggregat ...

  9. Decoders Matter for Semantic Segmentation:Data-Dependent Decoding Enables Flexible Feature Aggregation

    Decoders Matter for Semantic Segmentation:Data-Dependent Decoding Enables Flexible Feature Aggregati ...

随机推荐

  1. slice,splice,substr,substring函数的区别

    slice: 语法:array.slice(startIndex,endIndex); 参数: startIndex:必须,规定从何处开始选取,如果为负则从尾部开始计算 : endIndex:可选,规 ...

  2. HDU 6268 Master of Subgraph (2017 CCPC 杭州 E题,树分治 + 树上背包)

    题目链接  2017 CCPC Hangzhou  Problem E 题意  给定一棵树,每个点有一个权值,现在我们可以选一些连通的点,并且把这点选出来的点的权值相加,得到一个和. 求$[1, m] ...

  3. 【spring mvc】后台API查询接口,get请求,后台Date字段接收前台String类型的时间,报错default message [Failed to convert property value of type 'java.lang.String' to required type 'java.util.Date' for property 'createDate';

    后台API查询接口,get请求,后台Date字段接收前台String类型的时间筛选条件 后台接口接收 使用的实体 而createDate字段在后台实体中是Date类型 报错信息: org.spring ...

  4. Snapdragon profiler连不上 android手机

    adb devices也是空 开发者选项里面该开的都开了 就可以了 对了数据线不对也会连不上...

  5. 排序算法的实现(冒泡,选择,插入 O(N*N)--理解方法实现

    以前也看过很多排序算法的原理,每次都想自己实现一下,一直都再拖,现在着牛课网学习算法课程,希望自己能够坚持练习. //对于一个int数组,请编写一个选择冒泡算法,对数组元素排序. //给定一个int数 ...

  6. python项目构建工具zc.buildout

    转载:http://blog.csdn.net/u011630575/article/details/52940099 buildout简介 Buildout 是一个基于Python的构建工具, Bu ...

  7. curl 执行post请求

    #curl -l -H "Content-type: application/json;charset=UTF-8" -H "X-Forwarded-For: 20.20 ...

  8. Java 学习之网络编程案例

    网络编程案例 一,概念 1,网络编程不等于网站编程 2,编程只和传输层打交道,即TCP和UDP两个协议 二,案例 1,TCP实现点对点的聊天 Server端:两个输入流:读客户端和控制台,一个输出端: ...

  9. 转 : SQL Server数据库优化经验总结

    优化数据库的注意事项: 1.关键字段建立索引. 2.使用存储过程,它使SQL变得更加灵活和高效. 3.备份数据库和清除垃圾数据. 4.SQL语句语法的优化.(可以用Sybase的SQL Expert, ...

  10. 百度地图 Android SDK - 标注(Marker)的基本使用

    标注(Marker)是开发人员最常使用的地图覆盖物志一.今天就来向大家介绍一些标注(Marker)的最基本用法! 实现目标: 1.构建基础地图页面: 2.在地图的中心点处加入 Marker: 3.实现 ...