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. Go丨语言学习笔记--switch

    Java语言与Go语言的switch对比 Go语言 switch str { case "yes" : do something ... case "no" d ...

  2. animation-delay负值

    <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...

  3. AtCoder Grand Contest #026 C - String Coloring

    Time Limit: 3 sec / Memory Limit: 1024 MB Score : 600600 points Problem Statement You are given a st ...

  4. bzoj 2850: 巧克力王国 K-D树

    题目大意 http://www.lydsy.com/JudgeOnline/problem.php?id=2850 题解 对于每个人,我们发现它能够接受的巧克力中 如果对参数分别讨论,那么一定是一个连 ...

  5. vue之axios请求数据本地json

    写给自己的话:静态的json文件要记得放在static文件夹下,想打自己 1.下载插件 npm install axios --save 2.在main.js下引用axios import axios ...

  6. BZOJ3648:寝室管理

    浅谈树分治:https://www.cnblogs.com/AKMer/p/10014803.html 题目传送门:https://www.lydsy.com/JudgeOnline/problem. ...

  7. Advanced R之函数

    转载请注明出处,谢谢. 再次声明下,本人水平有些,错误之处敬请指正. 函数 函数是R基本的块结构单元:为了掌握本书中的更高级技术,你需要对函数有扎实的了解.也许你已经写过一些函数,并了解函数的基本知识 ...

  8. K-S Test

    K-S test, test for the equality of continuous, one-dimensional probability distribution that can be ...

  9. 《精通Spring4.X企业应用开发实战》读后感第五章(装配Bean,依赖注入)

  10. 面试总结hashmap

    考点: 1.hashing的概念 2.HashMap中解决碰撞的方法 3.equals()和hashCode()的应用,以及它们在HashMap中的重要性 4.不可变对象的好处 5.HashMap多线 ...