Canada Cup 2016 C. Hidden Word

时间:2022-10-06 08:55:09
C. 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

思路:先将初始字符串t删去重复的字母,然后按初始的顺序枚举可能的字符组合(26种),将其分成两行,判断是否符合条件即可。
总结:这是一道思维题,简单搜索的部分,也是对编码功底的锻炼。写了(改了)好久,好久。。
代码:
 #include "cstdio"
#include "algorithm"
#include "cstring"
#include "queue"
#include "cmath"
#include "vector"
#include "map"
#include "stdlib.h"
#include "set"
typedef long long ll;
using namespace std;
const int N=1e4+;
const int mod=1e9+;
#define db double
//int a[N];
//set<int> q;
//map<int ,int > u;
//ll dp[N];
char t[];
char f[];
int m=,pd;
int a[],b[];
char s[][],g[];
int d[][]={{,},{,-},{,},{-,},{-,-},{-,},{,},{,-}};//刚开始没带等号
void dfs(int x,int y,int m){
if(m==) pd=;//m写成26了,最后的错误
a[s[x][y]-'A']--;
for(int i=;i<;i++){
int nx=x+d[i][],ny=y+d[i][];
if(nx>=&&nx<&&ny>=&&ny<&&s[nx][ny]==g[m]&&a[s[nx][ny]-'A']>) {
dfs(nx, ny, m + );
}
}
}
int main()
{
scanf("%s",t);
strcpy(g,t);
char e,v;
for(int i=;i<;i++){
if(t[i]==t[i+]) {puts("Impossible");return ;}
v=t[i];
a[v-'A']++;//'A'写成'a'一直没查出来
if(a[v-'A']==) {
e=v;
for(int j=i+;j<;j++)
a[t[j]-'A']++;
for(int j=i+;j<;){
t[i++]=t[j++];
}
}
}
for(int i=;i<;i++){
b[i]=a[i];
t[i+]=t[i];
}
for(int i=;i<;i++){
int p=;
for(int j=i;j<+i;){
f[p++]=t[j++];
}
int k=;
for(int l=;l<;l++) s[][l]=f[l];//开始数组开13,开小了
for(int l=;l>=;l--) s[][l]=f[k++];
pd=;
for(int ii=;ii<;ii++){
for(int j=;j<;j++){
if(s[ii][j]==t[]){
dfs(ii,j,);
if(pd) {
for(int kk=;kk<;kk++)
puts(s[kk]);
return ;
}
}
}
}
memcpy(a,b, sizeof(a));
}
return ;
}

Canada Cup 2016 C. Hidden Word的更多相关文章

  1. Canada Cup 2016 C&period; Hidden Word 构造模拟题

    http://codeforces.com/contest/725/problem/C Each English letter occurs at least once in s. 注意到题目有这样一 ...

  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&period; Contest Balloons

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

  5. Canada Cup 2016 D&period; Contest Balloons 好题。优先队列 &plus; 简单贪心

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

  6. CodeForces Canada Cup 2016【A&comma;B&comma;C&comma;D】

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

  7. Hidden Word

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

  8. &lbrack;Google Codejam&rsqb; Round 1A 2016 - The Last Word

    [Problem Description] Problem On the game show The Last Word, the host begins a round by showing the ...

  9. VK Cup 2016 - Round 1 &lpar;Div&period; 2 Edition&rpar; A&period; Bear and Reverse Radewoosh 水题

    A. Bear and Reverse Radewoosh 题目连接: http://www.codeforces.com/contest/658/problem/A Description Lima ...

随机推荐

  1. 继续上篇抢QQ口令红包,抢那招抢不了的红包技巧

    - - - - - - - - - - -- - - --长按红包,出现回复,点击回复,那回复里有个表情,直接输入那个表情回复就可以抢了 - - - - - - - - --------------- ...

  2. &lbrack;WCF编程&rsqb;12&period;事务:事务传播

    一.事务传播概述 WCF可以跨越服务边界传递事务.这可以让服务参与到客户端事务里,客户端还可以在同一个事务里调用多个服务.客户端本身不一定是WCF服务.客户端事务是否传播到服务端可以通过绑定和操作契约 ...

  3. 移动端App广告常见的10种形式

    什么是App广告?   App广告,或称In-App广告,是指智能手机和平板电脑这类移动设备中第三方应用程序内置广告,属于移动广告的子类别. App广告兴起得益于其载体—App的风行.平板电脑和大屏触 ...

  4. Windows Store Apps&comma; Error&colon; The certificate specified has expired&period;(转)

    Windows Store Apps, Error: The certificate specified has expired. 0 comments|Posted on October 7th, ...

  5. Windows下文件的所有和权限

    跟linux不同, 在linux下 ,文件的所有者,就拥有对文件的所有读写执行的权限, 而windows, 文件的所有者不一定对文件拥有所有的权限, 场景: 要对系统文件(windows\system ...

  6. Azure SQL 数据库与新的数据库吞吐量单位

    在这一期中,Scott 与 Azure SQL 数据库性能首席项目经理主管 Tobias Ternstrom 一起详细阐释了新的数据库吞吐量单位 (Database Throughput Unit, ...

  7. Java方法区(Method Area)

    方法区与Java堆一样,是各个线程共享的内存区域,他在与存储已被虚拟机加载的类信息,常量,静态变量,即时编译器编译后的代码等数据,虽然Java虚拟机规范把方法区描述为堆得一个逻辑部分,但是他却有一个别 ...

  8. vue如何在路由跳转的时候更新组件

    项目中在路由跳转的时候碰到一个问题,没有更新视图,如何解决呢: https://segmentfault.com/a/1190000008879966 http://www.tuicool.com/a ...

  9. 如何使用 Jenkins、GitHub 和 Docker 在 Azure 中的 Linux VM 上创建开发基础结构

    若要将应用程序开发的生成和测试阶段自动化,可以使用持续集成和部署 (CI/CD) 管道. 本教程介绍如何在 Azure VM 上创建 CI/CD 管道,包括如何: 创建 Jenkins VM 安装并配 ...

  10. IIS 搭建

    1. 在打开程序功能里面,点击IIS安装.注意要选择适当的各种有用的服务.例如默认文档就需要安装非IIS下面的选项. 2. IIS部署网站可以参考网上的步骤.会遇到500处理程序“Extensionl ...