Shuffle'm Up
Time Limit: 1000MS   Memory Limit: 65536K
Total Submissions: 10766   Accepted: 4976

Description

A common pastime for poker players at a poker table is to shuffle stacks of chips. Shuffling chips is performed by starting with two stacks of poker chips, S1 and S2, each stack containing C chips. Each stack may contain chips of several different colors.

The actual shuffle operation is performed by interleaving a chip from S1 with a chip from S2 as shown below for C = 5:

The single resultant stack, S12, contains 2 * C chips. The bottommost chip of S12 is the bottommost chip from S2. On top of that chip, is the bottommost chip from S1. The interleaving process continues taking the 2nd chip from the bottom of S2and placing that on S12, followed by the 2nd chip from the bottom of S1 and so on until the topmost chip from S1 is placed on top of S12.

After the shuffle operation, S12 is split into 2 new stacks by taking the bottommost C chips from S12 to form a new S1 and the topmost C chips from S12 to form a new S2. The shuffle operation may then be repeated to form a new S12.

For this problem, you will write a program to determine if a particular resultant stack S12 can be formed by shuffling two stacks some number of times.

Input

The first line of input contains a single integer N, (1 ≤ N ≤ 1000) which is the number of datasets that follow.

Each dataset consists of four lines of input. The first line of a dataset specifies an integer C, (1 ≤ C ≤ 100) which is the number of chips in each initial stack (S1 and S2). The second line of each dataset specifies the colors of each of the C chips in stack S1, starting with the bottommost chip. The third line of each dataset specifies the colors of each of the C chips in stack S2 starting with the bottommost chip. Colors are expressed as a single uppercase letter (A through H). There are no blanks or separators between the chip colors. The fourth line of each dataset contains 2 * C uppercase letters (A through H), representing the colors of the desired result of the shuffling of S1 and S2 zero or more times. The bottommost chip’s color is specified first.

Output

Output for each dataset consists of a single line that displays the dataset number (1 though N), a space, and an integer value which is the minimum number of shuffle operations required to get the desired resultant stack. If the desired result can not be reached using the input for the dataset, display the value negative 1 (−1) for the number of shuffle operations.

Sample Input

2
4
AHAH
HAHA
HHAAAAHH
3
CDE
CDE
EEDDCC

Sample Output

1 2
2 -1

Source

这实际上是一个模拟题啊,怎么在搜索里面呢
 #include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm> using namespace std; int main()
{
int n,cc;
char a[],b[],c[];
char result[];
int cou=;
scanf("%d",&n);
for(int i=;i<n;i++){
int j;
scanf("%d",&cc);
scanf("%s",a);
scanf("%s",b);
scanf("%s",result);
for(j=;j<cc*;j++){//注意最多循环cc*2次就会恢复第一次的序列
cou=;
for(int k=;k<cc;k++){
c[cou++]=b[k];
c[cou++]=a[k];
}
c[cou]='\0';
int ans=strcmp(c,result);
if(ans==){
printf("%d %d\n",i+,j+);
break;
}
for(int l=;l<cc;l++){
a[l]=c[l];
b[l]=c[l+cc];
}
}
if(j==cc*){
printf("%d %d\n",i+,-);
}
}
return ;
}

poj3087 Shuffle'm Up(模拟)的更多相关文章

  1. POJ3087:Shuffle'm Up(模拟)

    http://poj.org/problem?id=3087 Description A common pastime for poker players at a poker table is to ...

  2. POJ3087 Shuffle'm Up(模拟)

    题目链接. AC代码如下; #include <iostream> #include <cstdio> #include <cstring> #include &l ...

  3. POJ-3087 Shuffle'm Up (模拟)

    Description A common pastime for poker players at a poker table is to shuffle stacks of chips. Shuff ...

  4. POJ3087 Shuffle'm Up 简单模拟

    题意:就是给你两副扑克,然后一张盖一张洗牌,不断重复这个过程,看能不能达到目标的扑克顺序 分析:然后就模拟下,-1的情况就是有循环节 #include<cstdio> #include&l ...

  5. 【POJ - 3087】Shuffle'm Up(模拟)

    Shuffle'm Up 直接写中文了 Descriptions: 给定两个长度为len的字符串s1和s2, 接着给出一个长度为len*2的字符串s12. 将字符串s1和s2通过一定的变换变成s12, ...

  6. poj 3087 Shuffle'm Up (模拟过程)

    Description A common pastime for poker players at a poker table is to shuffle stacks of chips. Shuff ...

  7. POJ3087 Shuffle'm Up —— 打表找规律 / map判重

    题目链接:http://poj.org/problem?id=3087 Shuffle'm Up Time Limit: 1000MS   Memory Limit: 65536K Total Sub ...

  8. poj3087 Shuffle'm Up

    Description A common pastime for poker players at a poker table is to shuffle stacks of chips. Shuff ...

  9. POJ 3078 - Shuffle'm Up - [模拟题]

    题目链接:http://poj.org/problem?id=3087 Description A common pastime for poker players at a poker table ...

随机推荐

  1. Wordpress上一篇文章和下一篇文章

    <div class="chapter"> <div class="prev"><?php previous_post_link( ...

  2. JS数字指定长度不足前补零的实现

    问题描述:         要求输出的数字长度是固定的,如长度为2,数字为1,则输出01,即不够位数就在之前补足0. 解决方法: 方法1 function fn1(num, length) { ret ...

  3. 浅谈MFC类CrackMe中消息处理函数查找方法

    最近一个学姐发给我了一份CrackMe希望我解一下,其中涉及到了MFC的消息函数查找的问题,就顺便以此为例谈一下自己使用的消息函数查找的方法.本人萌新,如果有任何错漏与解释不清的地方,欢迎各路大佬指正 ...

  4. 用GO开发企业级分布式云存储系统

    一.基础架构 二.开发工具

  5. linux go环境安装和基本项目结构

    最近项目中要用到Go语言,所以简单总结一下安装和配置,Go这个语言本身就限定了很多规范,比如项目设置,编程风格等,开发中就不需要再因为各种规范问题纠结了,直接用官方规定的能避免很多坑,下面直接切正题, ...

  6. 【转】最近很火的 Safe Area 到底是什么

    iOS 7 之后苹果给 UIViewController 引入了 topLayoutGuide 和 bottomLayoutGuide 两个属性来描述不希望被透明的状态栏或者导航栏遮挡的最高位置(st ...

  7. Python性能分析

    Python性能分析 https://www.cnblogs.com/lrysjtu/p/5651816.html https://www.cnblogs.com/cbscan/articles/33 ...

  8. spring拦截器中使用spring的自动注入

    需要在spring的拦截器中使用自定义的服务,这要就设计到将服务注入到拦截器中.网上看的情况有两种: 1. @Configuration public class OptPermissionHandl ...

  9. IoC之AutoFac(一)——简单使用和组件注册

    阅读目录 一.AutoFac简单使用 二.注册 2.1 注册方式 2.2 带参数注册 回到顶部 一.AutoFac简单使用 1 namespace AutofacDemo 2 { 3 class Pr ...

  10. 【Python】解析Python的缩进规则

    Python中的缩进(Indentation)决定了代码的作用域范围.这一点和传统的c/c++有很大的不同(传统的c/c++使用花括号花括号{}符决定作用域的范围:python使用缩进空格来表示作用域 ...