SWERC 2013 D - Decoding the Hallway

 题目PDF

提交地址

找规律 

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

check if the given pattern is substring of S[i]  for i<= n.

#include<iostream>
#include<cstring>
#include<cstdio>
#include<string>
#include<algorithm>
using namespace std;
#define ll long long

int N=10;
string s[11];

string f(string s)
{
    reverse(s.begin(),s.end());
    int n=s.size();
    for(int i=0;i<n;i++) s[i]=s[i]=='L'?'R':'L';
    return s;
}
int main()
{
    s[1]="L";
    for(int i=1;i<10;i++)
    {
        s[i+1]=s[i]+"L"+f(s[i]);
    }
    for(int i=1;i<=10;i++)
        cout<<s[i]<<' '<<s[i].size()<<endl;
    int n ;
    int re; cin>>re; int ca=1;
    while(re--)
    {
        string a;
        cin>>n>>a;
        n=min(n,N);
        bool ok=0;
        for(int i=1;i<=n;i++)
            if((int)a.size()<=(int)s[i].size()&&s[i].find(a)!=a.npos)
                ok=1;
        printf("Case %d: %s\n",ca++,ok?"Yes":"No");
    }
}


你可能感兴趣的:(SWERC 2013 D - Decoding the Hallway)