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 ...
随机推荐
- git config and options core.bare hard
In Lynda course Building a Web Interface with React.js 003 Using the exercises > git clone --bare ...
- 7 个 jQuery 最佳实践
前言 随着富网络应用(rich web applications)数量的增长,以及用户对快速交互响应的高期望,开发者开始使用JavaScript库来快速高效的完成一些重复性的工作.这其中最流行的Jav ...
- MC- 挂单STOP交易
using System; using System.Drawing; using System.Linq; using PowerLanguage.Function; using ATCenterP ...
- tomcat源码分析(一)
tomcat的启动从Bootstrap类的main方法开始. public static void main(String args[]) { //单例 if (daemon == null) { d ...
- spring容器启动的加载过程(三)
第十步: public class XmlBeanDefinitionReader extends AbstractBeanDefinitionReader { /** * Load bean def ...
- CSS3 transform的demo1
<!DOCTYPE html> <html> <head> <title>弹出层演示</title> <meta charset=&q ...
- RPM安装gcc gcc-c++扩展
rpm -ivh cpp--.el5.i386.rpm 回车 rpm -ivh kernel-headers--.el5.i386.rpm 回车 rpm -ivh glibc-headers-.i38 ...
- onmousedown活用之碰撞效果
通过绝对定位,在页面中随意位置设置两个div; 也就是说div 是拖动的框,div1和div2是被触碰的框; <!DOCTYPE html> <html> <head&g ...
- 简析TCP的三次握手与四次分手【转】
转自 简析TCP的三次握手与四次分手 | 果冻想http://www.jellythink.com/archives/705 TCP是什么? 具体的关于TCP是什么,我不打算详细的说了:当你看到这篇文 ...
- 生成SQL脚本的方法
2点需要注意的关键: (1)选择特定数据库对象不包含用户选项: (2)要编写脚本的数据的类型选择"架构和数据".