poj3087 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(模拟)的更多相关文章
- POJ3087:Shuffle'm Up(模拟)
http://poj.org/problem?id=3087 Description A common pastime for poker players at a poker table is to ...
- POJ3087 Shuffle'm Up(模拟)
题目链接. AC代码如下; #include <iostream> #include <cstdio> #include <cstring> #include &l ...
- POJ-3087 Shuffle'm Up (模拟)
Description A common pastime for poker players at a poker table is to shuffle stacks of chips. Shuff ...
- POJ3087 Shuffle'm Up 简单模拟
题意:就是给你两副扑克,然后一张盖一张洗牌,不断重复这个过程,看能不能达到目标的扑克顺序 分析:然后就模拟下,-1的情况就是有循环节 #include<cstdio> #include&l ...
- 【POJ - 3087】Shuffle'm Up(模拟)
Shuffle'm Up 直接写中文了 Descriptions: 给定两个长度为len的字符串s1和s2, 接着给出一个长度为len*2的字符串s12. 将字符串s1和s2通过一定的变换变成s12, ...
- poj 3087 Shuffle'm Up (模拟过程)
Description A common pastime for poker players at a poker table is to shuffle stacks of chips. Shuff ...
- POJ3087 Shuffle'm Up —— 打表找规律 / map判重
题目链接:http://poj.org/problem?id=3087 Shuffle'm Up Time Limit: 1000MS Memory Limit: 65536K Total Sub ...
- poj3087 Shuffle'm Up
Description A common pastime for poker players at a poker table is to shuffle stacks of chips. Shuff ...
- POJ 3078 - Shuffle'm Up - [模拟题]
题目链接:http://poj.org/problem?id=3087 Description A common pastime for poker players at a poker table ...
随机推荐
- ESP8266 NOOS SDK libat.a Functions
at_baseCmd.o custom_infoat_baseCmd.o at_exeCmdNullat_baseCmd.o at_setupCmdEat_baseCmd.o at_exeCmdRst ...
- Deepin 15.4 破解安装 SecureFX-7.3 失败
参考先前的文章(Ubuntu 14 安装并破解SSH工具 SecureCRT),破解安装 SecureCRT-7.3 成功,但是破解安装 SecureFX-7.3 时就一直报错: Insuffici ...
- JSOUP 打开url的方式
一般采用这种方式: try{ doc = Jsoup.connect(url) .header("User-Agent", "Mozilla/5.0 (Windows N ...
- js -- 绑定的click addEventListener 事件只触发一次
var btn = document.getElementById('btn'); // 添加事件绑定 btn.addEventListener('click', btnClick, false); ...
- sql server ExecuteNonQuery()返回受影响行数不适用select语句
SqlCommand.ExecuteNonQuery 方法对连接执行 Transact-SQL 语句并返回受影响的行数. 对于 UPDATE.INSERT 和 DELETE 语句,返回值为该命令所影响 ...
- 使用wrk进行压力测试
最近需要对新的服务进行压力测试.比较了ab和jemeter以及wrk.最终选择wrk来作为压力测试工具,可以把cpu压到100%. 官方源码: https://github.com/wg/wrk 安装 ...
- linux中Ctrl+D,Ctrl+Z,Ctrl+C
1.用stty -a查看控制字符的终端配置 2. ctrl-c 是发送 SIGINT 信号.终止一个进程 ctrl-z 是发送 SIGSTOP信号,挂起一个进程;命令fg唤回进程. ctrl-d 不是 ...
- mac ssh 连接超时
打开终端,进入,/etc/ssh.sudo vi ssh_config 最后一行添加 ServerAliveInterval30 然后保存就可以了
- IDEA使用笔记(十)——设置Java方法注释
如果你看到了,这篇博文,那么你是幸运的!你问什么?你百度百度同类型的网文就明白了! 一:先看效果 二:我的实验过程(肯定还有别的方式) 1:新建 Template Group,详细操作步骤见下图 ...
- 构建自己的 Smart Life 私有云(二)-> 连通 IFTTT & Slack
博客搬迁至https://blog.wangjiegulu.com RSS订阅:https://blog.wangjiegulu.com/feed.xml 原文链接:https://blog.wang ...