找规律

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. N皇后问题(C++实现和函数式编程实现)

    题意 在 N * N 的方格棋盘放置了 N 个皇后,使得它们不相互攻击(即任意2个皇后不允许处在同一排,同一列,也不允许处在与棋盘边框成45角的斜线上.求出有多少种合法的放置方法. C++实现(位运算 ...

  2. jQuery笔记:checkbox

    用jQuery操作checkbox时的一点小问题. 勾选checkbox的时候,$("#id").attr("checked")变为"checked& ...

  3. outlook preview setup

    ow To Show Subject Above/Below Sender In Mail List In Outlook? Normally in the compact view of a mai ...

  4. Oracle 查询每天执行慢的SQL

    本文转载自http://blog.itpub.net/28602568/viewspace-1364844/ 前言:  工作中的您是否有 想对每天慢的sql进行查询.汇总或者行优化等情况,如下SQL希 ...

  5. luogu P1164 小A点菜

    题目背景 uim神犇拿到了uoi的ra(镭牌)后,立刻拉着基友小A到了一家……餐馆,很低端的那种. uim指着墙上的价目表(太低级了没有菜单),说:“随便点”. 题目描述 不过uim由于买了一些辅(e ...

  6. BZOJ2038 [2009国家集训队]小Z的袜子(hose)(莫队算法)

    神奇的莫队算法,用来解决可离线无修改的区间查询问题: 首先对原序列进行分块,√n块每块√n个: 然后对所有查询的区间[l,r]进行排序,首先按l所在的块序号升序排序,如果一样就按r升序排序: 最后就按 ...

  7. 3.非标准的NDEF格式数据解析--IsoDep

    1.使用目的:正常开发是针对NDEF格式数据进行开发,但实际情况并非如此,以厦门公交卡为例,厦门公交卡保存的是非NDEF格式数据.其类型是IsoDep类型. 2.非标准的NDEF格式数据流程:当厦门公 ...

  8. Apache压力(并发)测试工具ab的使用教程收集

    说明:用ab的好处,在处理多并发的情况下不用自己写线程模拟.其实这个世界除了LoadRunner之外还是有很多方案可以选择的. 官网: http://httpd.apache.org/(Apache服 ...

  9. 手把手教你使用FineUI+动软代码生成器开发一个b/s结构的取送货管理信息系统(附源码)之开篇

    一 本系列随笔概览及产生的背景 近阶段接到一些b/s类型的软件项目,但是团队成员之前大部分没有这方面的开发经验,于是自己选择了一套目前网上比较容易上手的开发框架(FineUI),计划录制一套视频讲座, ...

  10. Android Linux内核编译

    平台: Wind7_64 + Ubuntu12_04_64 + VMware 这里以Android5.0为例: Android5.0 可以到这里下载:115网盘礼包码:5lbd7crtk1wzhttp ...