zoukankan      html  css  js  c++  java
  • Hidden Word

    Hidden Word
    time limit per test
    2 seconds
    memory limit per test
    256 megabytes
    input
    standard input
    output
    standard output

    Let’s define a grid to be a set of tiles with 2 rows and 13 columns. Each tile has an English letter written in it. The letters don't have to be unique: there might be two or more tiles with the same letter written on them. Here is an example of a grid:

    ABCDEFGHIJKLM
    NOPQRSTUVWXYZ

    We say that two tiles are adjacent if they share a side or a corner. In the example grid above, the tile with the letter 'A' is adjacent only to the tiles with letters 'B', 'N', and 'O'. A tile is not adjacent to itself.

    A sequence of tiles is called a path if each tile in the sequence is adjacent to the tile which follows it (except for the last tile in the sequence, which of course has no successor). In this example, "ABC" is a path, and so is "KXWIHIJK". "MAB" is not a path because 'M' is not adjacent to 'A'. A single tile can be used more than once by a path (though the tile cannot occupy two consecutive places in the path because no tile is adjacent to itself).

    You’re given a string s which consists of 27 upper-case English letters. Each English letter occurs at least once in s. Find a grid that contains a path whose tiles, viewed in the order that the path visits them, form the string s. If there’s no solution, print "Impossible" (without the quotes).

    Input

    The only line of the input contains the string s, consisting of 27 upper-case English letters. Each English letter occurs at least once in s.

    Output

    Output two lines, each consisting of 13 upper-case English characters, representing the rows of the grid. If there are multiple solutions, print any of them. If there is no solution print "Impossible".

    Examples
    input
    ABCDEFGHIJKLMNOPQRSGTUVWXYZ
    output
    YXWVUTGHIJKLM
    ZABCDEFSRQPON
    input
    BUVTYZFQSNRIWOXXGJLKACPEMDH
    output
    Impossible
    分析:注意观察除了相邻的两个字符以外,其他都可以,模拟即可;
    代码:
    #include <iostream>
    #include <cstdio>
    #include <cstdlib>
    #include <cmath>
    #include <algorithm>
    #include <climits>
    #include <cstring>
    #include <string>
    #include <set>
    #include <map>
    #include <unordered_map>
    #include <queue>
    #include <stack>
    #include <vector>
    #include <list>
    #define rep(i,m,n) for(i=m;i<=n;i++)
    #define rsp(it,s) for(set<int>::iterator it=s.begin();it!=s.end();it++)
    #define mod 1000000007
    #define inf 0x3f3f3f3f
    #define vi vector<int>
    #define pb push_back
    #define mp make_pair
    #define fi first
    #define se second
    #define ll long long
    #define pi acos(-1.0)
    #define pii pair<int,int>
    #define Lson L, mid, ls[rt]
    #define Rson mid+1, R, rs[rt]
    #define sys system("pause")
    const int maxn=2e5+10;
    using namespace std;
    ll gcd(ll p,ll q){return q==0?p:gcd(q,p%q);}
    ll qpow(ll p,ll q){ll f=1;while(q){if(q&1)f=f*p;p=p*p;q>>=1;}return f;}
    inline ll read()
    {
        ll x=0;int f=1;char ch=getchar();
        while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
        while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
        return x*f;
    }
    int n,m,k,t,cnt[300],ok,pos;
    string a;
    char ans[2][14];
    int main()
    {
        int i,j;
        ans[0][13]=ans[1][13]=0;
        memset(cnt,-1,sizeof(cnt));
        cin>>a;
        for(i=0;a[i];i++)
        {
            if(cnt[a[i]]!=-1)ok=i-cnt[a[i]]-1,pos=cnt[a[i]];
            else cnt[a[i]]=i;
        }
        if(!ok)return 0*puts("Impossible");
        int cnt;
        ans[0][12-ok/2]=a[pos];
        for(i=13-ok/2,cnt=1;i<13;i++,cnt++)ans[0][i]=a[pos+cnt];
        for(i=12;i>=13-ok/2;i--,cnt++)ans[1][i]=a[pos+cnt];
        if(ok&1)ans[1][i]=a[pos+cnt],cnt+=2,i--;else cnt++;
        for(;i>=0;i--,cnt++)ans[1][i]=a[pos+cnt>26?pos+cnt-27:pos+cnt];
        for(i=0;i<12-ok/2;cnt++,i++)ans[0][i]=a[pos+cnt>26?pos+cnt-27:pos+cnt];
        rep(i,0,1)printf("%s
    ",ans[i]);
        //system("Pause");
        return 0;
    }
  • 相关阅读:
    JqueryQrcode生成二维码不支持中文的解决办法
    [转载]浅析海量用户的分布式系统设计
    [转载]大型网站应用中 MySQL 的架构演变史
    CSS3变形记(上):千变万化的Div
    JavaScript进阶之路——认识和使用Promise,重构你的Js代码
    Visual Studio Code预览版Ver 0.3.0试用体验
    Apache Spark 2.3.0 正式发布
    Apache Spark 2.2.0 新特性详细介绍
    Apache Spark 2.2.0 正式发布
    Spark 论文篇-论文中英语单词集
  • 原文地址:https://www.cnblogs.com/dyzll/p/6002472.html
Copyright © 2011-2022 走看看