码迷,mamicode.com
首页 > 其他好文 > 详细

Canada Cup 2016 C. Hidden Word

时间:2016-10-26 19:19:07      阅读:211      评论:0      收藏:0      [点我收藏+]

标签:cout   bit   second   cin   tor   tin   bsp   pre   ret   

题解:

构造题...当时想到了怎么做了。。

无奈码力太弱,一个位置写错了 fst

具体思路是。只要相同的字母不是相邻的,就一定可以构造

具体构造方法是把相同的字母的这一段放在最右边

xxxxxxxxx-----

xxxxxxxxxx----

如上图所示,然后X处就转圈画了..          

代码:

#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define mp make_pair
#define se second
#define fs first
#define LL long long
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1 
typedef pair<int,int> P;
const double eps=1e-9;
const int maxn=200100;
const int mod=1e9+7;
const int INF=1e9;

vector<int> v[30];
string s;
int a[30];

int main()
{
    cin>>s;
    for(int i=0;i<27;i++) v[s[i]-A].pb(i);
    int flag=0,pos,pre;
    for(int i=0;i<27;i++)
    {
        if(v[i].size()<=1) continue;
        for(int j=1;j<v[i].size();j++)
        {
            if(v[i][j]-v[i][j-1]!=1)
            {
                flag=1;
                pre=v[i][j-1];
                pos=v[i][j];
                break;
            }
        }
    }
    if(!flag) cout<<"Impossible"<<endl;
    else
    {
        int k=pos-pre;
        if(k%2)
        {
            k/=2;
            k++;
            for(int i=13-k+1;i<=13;i++) a[i]=pre++;
            k--;
            for(int i=26;i>=26-k+1;i--) a[i]=pre++;
            int j=26-k;
            for(j=26-k;j>=14;j--) 
            {
                ++pos;
                if(pos>26) break;
                a[j]=pos;
            }
            if(pos>26)
            {
                int m=0;
                if(j>=14)
                {
                    while(j>=14) a[j--]=m++;
                }
                j=1;
                while(j<13-k) a[j++]=m++;
            }
            else if(j<14)
            {
                j=1;
                pos++;
                while(pos<=26) a[j++]=pos++;
                int m=0;
                while(j<13-k) a[j++]=m++;
            }
        }
        else
        {
            k/=2;
            for(int i=13-k+1;i<=13;i++) a[i]=pre++;
            for(int i=26;i>=26-k+1;i--) a[i]=pre++;
            int j=26-k;
            for(j=26-k;j>=14;j--) 
            {
                ++pos;
                if(pos>26) break;
                a[j]=pos;
            }
            if(pos>26)
            {
                int m=0;
                if(j>=14)
                {
                    while(j>=14) a[j--]=m++;
                }
                j=1;
                while(j<=13-k) a[j++]=m++;
            }
            else if(j<14)
            {
                j=1;
                pos++;
                while(pos<=26) a[j++]=pos++;
                int m=0;
                while(j<=13-k) a[j++]=m++;
            }                        
        }
        for(int i=1;i<=13;i++) cout<<s[a[i]];
        cout<<endl;
        for(int i=14;i<=26;i++) cout<<s[a[i]];
        cout<<endl;
    }
    return 0;
}

 

Canada Cup 2016 C. Hidden Word

标签:cout   bit   second   cin   tor   tin   bsp   pre   ret   

原文地址:http://www.cnblogs.com/byene/p/6001118.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!