SWERC13 Decoding the Hallway, swerc13decoding

Source: Internet
Author: User

SWERC13 Decoding the Hallway, swerc13decoding

Search rules

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
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 th times in the picture.
Since Full Metal Alchemist Edward is so good, he did it perfectly. Now it is turn of
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
Left. So if n = 1, then the judge wowould have noted down L. If n = 2, it wowould have been LLR.
For n = 4, it wowould 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
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
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
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.
1 Problem 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;}




What is in the hallway?

I'm glad to answer your questions!
Hall, hallway US English corridor, channel.
In the hallway is in the hallway.
Hope to help you.

Please enter the decoding algorithm (0: Log-MAP, 1: SOVA) default 0 0 Please enter the frame size

The default value is zero. Enter 0 or press Enter. No need to change

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.