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 ...
随机推荐
- 异常处理汇总 ~ 修正果带着你的Code飞奔吧!
异常处理汇总-运维系列 http://www.cnblogs.com/dunitian/p/4522983.html 异常处理汇总-开发工具 http://www.cnblogs.com/dunit ...
- scipy.stats与统计学:4个概率分布:N,chi2,F,t
scipy.stats与统计学:4个概率分布:N,chi2,F,t 四个常用分布的概率密度函数.分布函数.期望.分位数.以及期望方差标准差中位数原点矩: 1,正态分布: from scipy.st ...
- 04、常用RDD操作整理
常用Transformation 注:某些函数只有PairRDD只有,而普通的RDD则没有,比如gropuByKey.reduceByKey.sortByKey.join.cogroup等函数要根据K ...
- 00、Word Count
1.开发环境 1.eclipse-jee-neon-3 2.scala-ide:http://download.scala-ide.org/sdk/lithium/e46/scala212/stabl ...
- DENIED Redis is running in protected mode
1.开源软件往往做的非常出色,错误的时候,会告诉你原因,以及怎么修改,仔细阅读就能明白.比如这个错误: [root@localhost src]# ./redis-cli -h 172.16.2.16 ...
- CentOS7 使用yum命令安装Java SDK(openjdk)
CentOS 6.X 和 7.X 自带有OpenJDK runtime environment (openjdk).它是一个在linux上实现开源的java 平台. 安装方式: 1.输入以下命令,以 ...
- 【PMP】项目整合管理
项目整合的七个过程组: 制定项目章程 制定项目管理计划 指导语管理项目工作 管理项目知识 监控项目工作 实施整体变更控制 结束项目或阶段 1.制定项目章程 1.1 定义 制定项目章程是编写一份正式批准 ...
- (原)faster rcnn的tensorflow代码的理解
转载请注明出处: https://www.cnblogs.com/darkknightzh/p/10043864.html 参考网址: 论文:https://arxiv.org/abs/1506.01 ...
- 分析轮子(九)- Cloneable.java
注:玩的是JDK1.7版本 一:Cloneable.java 接口也是标记接口,所以,它没有任何方法和属性,实现此接口表示的意思是:可以调用 Object.java 类的 clone() 方法,进行简 ...
- Software Engineer Title Ladder
http://changelog.ca/log/2013/08/09/software_engineer_title_ladder Within the software engineering pr ...