天天看点

Canada Cup 2016 C. Hidden Word 构造模拟题

​​http://codeforces.com/contest/725/problem/C​​

Each English letter occurs at least once in s.

注意到题目有这样一句话,那么就是说S中只有一个重复的字母。一定要看到这句话,不然做不了。

然后就找到pos1和pos2分别代表那两个字母的位置,把他们中间的所有字母对折一下,放在最右边就可以了。因为这样才能用上同一个位置。

只有连续两个相同的字母才会impossible,同样是因为只有两个相同的字母。

#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <algorithm>
#define IOS ios::sync_with_stdio(false)
using namespace std;
#define inf (0x3f3f3f3f)
typedef long long int LL;

#include <iostream>
#include <sstream>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <string>
const int maxn = 26 + 20;
char str[111];
int book[maxn];
char ans[maxn][maxn];
void work() {
//    for (int i = 1; i <= 2; ++i) {
//        for (int j = 1; j <= 13; ++j) {
//            ans[i][j] = 'a';
//        }
//    }
    scanf("%s", str + 1);
    for (int i = 1; i <= 27; ++i) {
        book[str[i]]++;
    }
    int pos[3];
    int cur = 1;
    for (int i = 1; i <= 27; ++i) {
        if (book[str[i]] == 2) pos[cur++] = i;
    }
    if (pos[1] == pos[2] - 1) {
        cout << "Impossible" << endl;
        return;
    }
//    cout << pos[1] << " " << pos[2] << endl;
    int ff = pos[1];
    int len = pos[2] - pos[1] - 1;
    int t = len / 2;
    ans[1][13 - t] = str[pos[1]];
    for (int i = 13 - t + 1; i <= 13; ++i) {
        ans[1][i] = str[++ff];
    }
    int flag = (len % 2) == 0;
    for (int i = 13; i >= 13 - t + flag; --i) {
        ans[2][i] = str[++ff];
    }

    int to = 13 - t - 1;
    cur = 1;
    if (to <= 0) {
        cur = 2;
        to = 1;
    }
    for (int i = pos[2] + 1; i <= 27; ++i) {
        ans[cur][to] = str[i];
        if (cur == 2) to++;
        else to--;
        if (to <= 0) {
            to = 1;
            cur = 2;
        }
    }
    for (int i = 1; i <= pos[1] - 1; ++i) {
        ans[cur][to] = str[i];
        if (cur == 2) to++;
        else --to;
        if (to <= 0) {
            to = 1;
            cur = 2;
        }
    }
    for (int i = 1; i <= 2; ++i) {
        for (int j = 1; j <= 13; ++j) {
            cout << ans[i][j];
        }
        cout << endl;
    }
}

int main() {
#ifdef local
    freopen("data.txt","r",stdin);
#endif
    work();
    return 0;
}