Hidden Word
2 seconds
256 megabytes
standard input
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).
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 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".
ABCDEFGHIJKLMNOPQRSGTUVWXYZ
YXWVUTGHIJKLM
ZABCDEFSRQPON
BUVTYZFQSNRIWOXXGJLKACPEMDH
Impossible
分析:注意观察除了相邻的两个字符以外,其他都可以,模拟即可;
代码:
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <climits>
#include <cstring>
#include <string>
#include <set>
#include <map>
#include <unordered_map>
#include <queue>
#include <stack>
#include <vector>
#include <list>
#define rep(i,m,n) for(i=m;i<=n;i++)
#define rsp(it,s) for(set<int>::iterator it=s.begin();it!=s.end();it++)
#define mod 1000000007
#define inf 0x3f3f3f3f
#define vi vector<int>
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define ll long long
#define pi acos(-1.0)
#define pii pair<int,int>
#define Lson L, mid, ls[rt]
#define Rson mid+1, R, rs[rt]
#define sys system("pause")
const int maxn=2e5+;
using namespace std;
ll gcd(ll p,ll q){return q==?p:gcd(q,p%q);}
ll qpow(ll p,ll q){ll f=;while(q){if(q&)f=f*p;p=p*p;q>>=;}return f;}
inline ll read()
{
ll x=;int f=;char ch=getchar();
while(ch<''||ch>''){if(ch=='-')f=-;ch=getchar();}
while(ch>=''&&ch<=''){x=x*+ch-'';ch=getchar();}
return x*f;
}
int n,m,k,t,cnt[],ok,pos;
string a;
char ans[][];
int main()
{
int i,j;
ans[][]=ans[][]=;
memset(cnt,-,sizeof(cnt));
cin>>a;
for(i=;a[i];i++)
{
if(cnt[a[i]]!=-)ok=i-cnt[a[i]]-,pos=cnt[a[i]];
else cnt[a[i]]=i;
}
if(!ok)return *puts("Impossible");
int cnt;
ans[][-ok/]=a[pos];
for(i=-ok/,cnt=;i<;i++,cnt++)ans[][i]=a[pos+cnt];
for(i=;i>=-ok/;i--,cnt++)ans[][i]=a[pos+cnt];
if(ok&)ans[][i]=a[pos+cnt],cnt+=,i--;else cnt++;
for(;i>=;i--,cnt++)ans[][i]=a[pos+cnt>?pos+cnt-:pos+cnt];
for(i=;i<-ok/;cnt++,i++)ans[][i]=a[pos+cnt>?pos+cnt-:pos+cnt];
rep(i,,)printf("%s\n",ans[i]);
//system("Pause");
return ;
}
Hidden Word的更多相关文章
- Canada Cup 2016 C. Hidden Word
C. Hidden Word time limit per test 2 seconds memory limit per test 256 megabytes input standard inpu ...
- Canada Cup 2016 C. Hidden Word 构造模拟题
http://codeforces.com/contest/725/problem/C Each English letter occurs at least once in s. 注意到题目有这样一 ...
- 【36.11%】【codeforces 725C】Hidden Word
time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...
- Codeforces Canada Cup 2016
A. Jumping Ball time limit per test 2 seconds memory limit per test 256 megabytes input standard inp ...
- codeforces 725/C
Hidden Word time limit per test 2 seconds memory limit per test 256 megabytes input standard input o ...
- dmalloc 原文 翻译整理
http://blog.csdn.net/cardinal_508/article/details/5553387 L13 从快速入门开始(Quickstart) 这个库是一个文件中所有简化用法中最常 ...
- c malloc分配内存
php中的内存分配有用类似emalloc这样的函数,emalloc实际上是C语言中的malloc的一层封装,php启动后,会向OS申请一块内存,可以理解为内存池,以后的php分配内存都是在这块内存池中 ...
- malloc.c
glibc-2.14中的malloc.c源代码,供研究malloc和free实现使用: /* Malloc implementation for multiple threads without lo ...
- 2017-2018 ACM-ICPC, NEERC, Southern Subregional Contest (Online Mirror, ACM-ICPC Rules, Teams Preferred)
先把代码扔上来 E. Field of Wonders time limit per test 3 seconds memory limit per test 256 megabytes input ...
随机推荐
- 第三次冲刺spring会议(第四次会议)
[例会时间]2014/5/23 21:15 [例会地点]9#446 [例会形式]轮流发言 [例会主持]马翔 [例会记录]兰梦 小组成员:兰梦 ,马翔,李金吉,赵天,胡佳奇
- spring容器启动的加载过程(二)
第六步: public abstract class AbstractApplicationContext extends DefaultResourceLoader implements Confi ...
- CSS中background:url(图片) 不能显示的问题
刚刚碰到一个奇怪的问题,这样一段CSS代码: .pho6 { background: url(img/pho6.jpg); } 这段代码居然不能显示出背景图片,路经绝对是没错的代码肯定没有问题, ...
- Chrome 自动填充的表单是淡黄色的背景怎么办!
chrome浏览器自动填充表单的黄色背景高亮(#FAFFBD)一直困扰着我,我之前没想着理它,可是最近一个登陆框,需要用到图标,于是我草率的直接设置在input元素里面,结果问题就来了,很难看很难看, ...
- Ajax.BeginForm 异步上传附件 替代方案
一:问题描述 含有文件信息表单内容,想通过异步上传到服务器,但是使用Ajax.BeginForm上传时,后台无法获取文件信息 二:解决方案 通过 $.ajaxFileUpload 可以实现文件及 ...
- How can I create an Asynchronous function in Javascript?
哈哈:)我的codepen 的代码笔记是:http://codepen.io/shinewaker/pen/eBwPxJ --------------------------------------- ...
- java类中为什么设置set和get方法操作属性
java程序规范中会建议大家尽量将类中的属性私有化,即定义为private变量,通过设置set和get函数来对属性进行操作.一些人存在这样的疑问,为什么不直接将属性设置为public,以后调用属性时直 ...
- DateUtils时间工具类探究
首先声明一下,这个DateUtils工具类不是自己写的,而是在commons-lang-2.Xjar包或是commons-lang3-3.X.jar包中,具体在哪个jar包中,看程序具体添加了哪个版本 ...
- Ant 删除目录 vs 清空目录
Apache Ant 可以用下面的命令来删除目录 <delete dir="${lucene.dir}"/> 但是这会删除整个目录,而我现在只想清空目录内的所有文件和子 ...
- 《OpenCV3编程入门》访问图像中像素的三类方法
·方法一 指针访问:C操作符[ ]; ·方法二 迭代器iterator; ·方法三 动态地址计算; #include <opencv2/core/core.hpp> #include &l ...