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 = + ;
char str[];
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 + );
for (int i = ; i <= ; ++i) {
book[str[i]]++;
}
int pos[];
int cur = ;
for (int i = ; i <= ; ++i) {
if (book[str[i]] == ) pos[cur++] = i;
}
if (pos[] == pos[] - ) {
cout << "Impossible" << endl;
return;
}
// cout << pos[1] << " " << pos[2] << endl;
int ff = pos[];
int len = pos[] - pos[] - ;
int t = len / ;
ans[][ - t] = str[pos[]];
for (int i = - t + ; i <= ; ++i) {
ans[][i] = str[++ff];
}
int flag = (len % ) == ;
for (int i = ; i >= - t + flag; --i) {
ans[][i] = str[++ff];
} int to = - t - ;
cur = ;
if (to <= ) {
cur = ;
to = ;
}
for (int i = pos[] + ; i <= ; ++i) {
ans[cur][to] = str[i];
if (cur == ) to++;
else to--;
if (to <= ) {
to = ;
cur = ;
}
}
for (int i = ; i <= pos[] - ; ++i) {
ans[cur][to] = str[i];
if (cur == ) to++;
else --to;
if (to <= ) {
to = ;
cur = ;
}
}
for (int i = ; i <= ; ++i) {
for (int j = ; j <= ; ++j) {
cout << ans[i][j];
}
cout << endl;
}
} int main() {
#ifdef local
freopen("data.txt","r",stdin);
#endif
work();
return ;
}

Canada Cup 2016 C. Hidden Word 构造模拟题的更多相关文章

  1. Canada Cup 2016 C. Hidden Word

    C. Hidden Word time limit per test 2 seconds memory limit per test 256 megabytes input standard inpu ...

  2. 【Codeforces Round 725】Canada Cup 2016

    模拟Canada Cup 2016,ABC三题,Rank1376 第三题卡住了 Codeforces 725 C 求出两个相同字符的位置,记为x和y. 然后考虑把相同的那个字符放在第一行的什么地方, ...

  3. Codeforces Canada Cup 2016

    A. Jumping Ball time limit per test 2 seconds memory limit per test 256 megabytes input standard inp ...

  4. Canada Cup 2016 D. Contest Balloons 好题。优先队列 + 简单贪心

    http://codeforces.com/contest/725/problem/D 这题一看就是贪心的了,w - t最小的那个,肯定是优先打死. 但是一直都不会写,为什么呢,因为这个太像二分答案了 ...

  5. CodeForces Canada Cup 2016【A,B,C,D】

    CodeForces 725A: 思路就是如果"最左"不是'>'这个了,那么这个右边的一定不可能到达左边了: 同理最右: CodeForces 725B: 有两个空姐,一个从 ...

  6. Canada Cup 2016 D. Contest Balloons

    最近好弱做什么题目都是做一晚上 这是合肥站炼铜后遗症? 这题就是贪心 我已开始还写了1小时---三分-----. #include<bits/stdc++.h> using namespa ...

  7. Hidden Word

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

  8. Schlumberger Petrel 2016.3 地震解释 油藏模拟

    Schlumberger Petrel 2016.3 地震解释 油藏模拟世界上顶尖的三维地质建模软件,软件为用户提供的工具可以用于地震解释.地质建模.油藏数 值模拟等方面的使用,清晰的地质模型可以描述 ...

  9. 剑指Offer——网易校招内推笔试题+模拟题知识点总结

    剑指Offer--网易校招内推笔试题+模拟题知识点总结 前言 2016.8.2 19:00网易校招内推笔试开始进行.前天晚上利用大约1小时时间完成了测评(这个必须做,关切到你能否参与面试).上午利用2 ...

随机推荐

  1. mysql之count

    两种引擎对count的处理 CREATE TABLE `test` ( `id` int(11) unsigned NOT NULL AUTO_INCREMENT, `name` char(15) D ...

  2. xpath normalize-sapce 函数的Java实现

    normalize-space函数实现的功能是:删除字符串前后空格,中间的空格有多个只保留一个. 1. 用Java正则表达式 public static String normalizeSpace(S ...

  3. 【Lintcode】017.Subsets

    题目: 题解: Solution 1 () class Solution { public: vector<vector<int> > subsets(vector<in ...

  4. visualVM远程监控JVM

    对于完全没用使用过visualVM的初学者 环境:Windows PC上使用visualVM监控远端JVM @@@@jstatd方式连接@@@@ 1.Windows安装jdk,$JAVA_HOME/b ...

  5. MongoDB 分片的原理、搭建、应用 !

    MongoDB 分片的原理.搭建.应用   一.概念: 分片(sharding)是指将数据库拆分,将其分散在不同的机器上的过程.将数据分散到不同的机器上,不需要功能强大的服务器就可以存储更多的数据和处 ...

  6. poj3254二进制放牛——状态压缩DP

    题目:http://poj.org/problem?id=3254 利用二进制压缩状态,每一个整数代表一行的01情况: 注意预处理出二进制表示下没有两个1相邻的数的方法,我的方法(不知为何)错了,看到 ...

  7. SQL 排序规则问题

    http://blog.csdn.net/delphigbg/article/details/12744807 MSSQL排序规则总结   什么是排序规则呢? 排序规则根据特定语言和区域设置标准指定对 ...

  8. [bzoj2301]Problem b莫比乌斯反演+分块优化

    题意: $\sum\limits_{\begin{array}{*{20}{c}}{a < = x < = b}\\{c < = y < = d}\end{array}} {\ ...

  9. Connection reset by peer的常见原因及解决办法

    转自:https://blog.csdn.net/xc_zhou/article/details/80950753 1,如果一端的Socket被关闭(或主动关闭,或因为异常退出而 引起的关闭),另一端 ...

  10. QualType in clang

    http://clang.llvm.org/docs/InternalsManual.html#the-qualtype-class the QualType class is designed to ...