找规律

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;
}

转载于:https://www.cnblogs.com/yangykaifa/p/6791232.html

SWERC13 Decoding the Hallway相关推荐

  1. 解决Python OpenCV 读取视频并抽帧出现error while decoding的问题

    解决Python OpenCV 读取视频抽帧出现error while decoding的问题 1. 问题 2. 解决 3. 源代码 参考 1. 问题 读取H264视频,抽帧视频并保存,报错如下: [ ...

  2. CAS (10) —— JBoss EAP 6.4下部署CAS时出现错误exception.message=Error decoding flow execution的解决办法...

    CAS (10) -- JBoss EAP 6.4下部署CAS时出现错误exception.message=Error decoding flow execution的解决办法 jboss版本: jb ...

  3. TypeError: decoding Unicode is not supported

    在试图读取网页的时候遇到TypeError: decoding Unicode is not supported, 主要原因是返回的字符串已经是unicode类型了 转载于:https://www.c ...

  4. [blog摘要]Exploring and Decoding ETW Providers using Event Log Channels

    这是一篇摘要,原文在这里 Exploring and Decoding ETW Providers using Event Log Channels (http://blogs.msdn.com/nt ...

  5. error: IO error while decoding xxx.jar with UTF-8

    问题复现: Spark-Second_Edition/第6章/src/main/scala$ scalac -cp self_jars/*.jar AssembleDocumentTermMatrix ...

  6. UVA - 213 Message Decoding

    Message Decoding UVA - 213 题目传送门 emmmm,此题按照紫书上的思路来即可,要么太复杂 AC代码: #include <cstdio> #include &l ...

  7. GO开发 -- could not launch process: decoding dwarf section info at offset 0x0: too short

    GO开发 -- 报错 decoding dwarf section offset 0x0 too short go语言升级到 go 1.11.4 版本后,IntelliJ IDEA 开发 go , d ...

  8. 2015-2020年各类国际会议与期刊基于图像的三维对象重建论文综述(4)—— 3D Surface decoding

    4. 3D Surface decoding 基于体素表示的方法在计算上非常浪费,因为信息仅在3D形状的表面上或附近丰富. 直接使用表面时的主要挑战是常见的表示(例如网格或点云)的结构不规则,因此它们 ...

  9. 2015-2020年各类国际会议与期刊基于图像的三维对象重建论文综述(3)——Volumetric decoding

    3. Volumetric decoding 体积表示将3D对象周围的空间区分为3D体素网格V. 离散度越精细,表示将越准确. 目标是恢复网格Vˆ =fθ(I),以使其表示的3D形状ˆX尽可能接近未知 ...

最新文章

  1. proguaid 混淆代码
  2. 求数组中第k个最小数
  3. sqlserver 查看进程以及查看死锁代码
  4. 买卖股票的最佳时机II
  5. AT2376-[AGC014D]Black and White Tree【结论,博弈论】
  6. python重复输出五句话_如何用python3输出重复的数据?
  7. BackgroundWorker学习笔记
  8. DWRUtil.addOptions
  9. oracle 表 队列,如何将复制队列表移出系统(SYSTEM)表空间
  10. Cmakelists 与gcc 调用so库文件,几个名词解释
  11. SQL注入漏洞-POST注入
  12. wegame显示密保服务器,wegame英雄联盟设置 | 手游网游页游攻略大全
  13. 性能测试tps上不去,又是redis的坑,说多了都是泪啊
  14. js网页右下角弹窗js特效
  15. python科研向数据处理篇——python-pptx批量向PPT中插入图片
  16. matlab中ode指令,matlab中ode5函数编写.doc
  17. 计算机表格增加,电脑中给Excel表格添加水印效果的方法
  18. 五款优质资源网站 每一个都让你欲罢不能
  19. 边缘计算开源框架EdgeXFoundry的部署应用开发(三)设备服务开发
  20. 国内外主流容灾备份厂商介绍

热门文章

  1. 【题解】LuoGu5514:[MtOI2019]永夜的报应
  2. 硅谷外卖学习日记之babelrc
  3. 25款Windows8系统最新高清桌面壁纸
  4. c语言正则表达式 windows,在C语言中使用正则表达式.doc
  5. 轻松设置百度搜索手写输入
  6. 模型ensemble
  7. Android TextView同时设置粗体和斜体
  8. Disruptor浅析
  9. Python之递归(含斐波那契数列和汉诺塔)
  10. 参数说明 - wxCharts使用文档