POJ 3087 Shuffle'm Up (模拟)

Shuffle'm Up

Time Limit: 1000MS Memory Limit: 65536K
Total Submissions: 5850 Accepted: 2744

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:

POJ 3087 Shuffle'm Up (模拟)


The single resultant stack, S12, contains 2 * Cvc3Ryb25nPjwvZW0+IGNoaXBzLiBUaGUgYm90dG9tbW9zdCBjaGlwIG9mIDxzdHJvbmc+UzxzdWI+MTI8L3N1Yj48L3N0cm9uZz4gaXMgdGhlIGJvdHRvbW1vc3QgY2hpcCBmcm9tIDxzdHJvbmc+UzxzdWI+Mjwvc3ViPjwvc3Ryb25nPi4gT24gdG9wIG9mIHRoYXQgY2hpcCwgaXMgdGhlIGJvdHRvbW1vc3QKIGNoaXAgZnJvbSA8c3Ryb25nPlM8c3ViPjE8L3N1Yj48L3N0cm9uZz4uIFRoZSBpbnRlcmxlYXZpbmcgcHJvY2VzcyBjb250aW51ZXMgdGFraW5nIHRoZSAyPHN1cD5uZDwvc3VwPiBjaGlwIGZyb20gdGhlIGJvdHRvbSBvZiA8c3Ryb25nPlM8c3ViPjI8L3N1Yj48L3N0cm9uZz4gYW5kIHBsYWNpbmcgdGhhdCBvbiA8c3Ryb25nPlM8c3ViPjEyPC9zdWI+PC9zdHJvbmc+LCBmb2xsb3dlZCBieSB0aGUgMjxzdXA+bmQ8L3N1cD4gY2hpcCBmcm9tIHRoZQogYm90dG9tIG9mIDxzdHJvbmc+UzxzdWI+MTwvc3ViPjwvc3Ryb25nPiBhbmQgc28gb24gdW50aWwgdGhlIHRvcG1vc3QgY2hpcCBmcm9tIDxzdHJvbmc+UzxzdWI+MTwvc3ViPjwvc3Ryb25nPiBpcyBwbGFjZWQgb24gdG9wIG9mIDxzdHJvbmc+UzxzdWI+MTI8L3N1Yj48L3N0cm9uZz4uPC9wPgo8cD5BZnRlciB0aGUgc2h1ZmZsZSBvcGVyYXRpb24sIDxzdHJvbmc+UzxzdWI+MTI8L3N1Yj48L3N0cm9uZz4gaXMgc3BsaXQgaW50byAyIG5ldyBzdGFja3MgYnkgdGFraW5nIHRoZSBib3R0b21tb3N0IDxlbT48c3Ryb25nPkM8L3N0cm9uZz48L2VtPiBjaGlwcyBmcm9tIDxzdHJvbmc+UzxzdWI+MTI8L3N1Yj48L3N0cm9uZz4gdG8gZm9ybSBhIG5ldyA8c3Ryb25nPlM8c3ViPjE8L3N1Yj48L3N0cm9uZz4gYW5kIHRoZSB0b3Btb3N0IDxlbT48c3Ryb25nPkM8L3N0cm9uZz48L2VtPiBjaGlwcwogZnJvbSA8c3Ryb25nPlM8c3ViPjEyPC9zdWI+PC9zdHJvbmc+IHRvIGZvcm0gYSBuZXcgPHN0cm9uZz5TPHN1Yj4yPC9zdWI+PC9zdHJvbmc+LiBUaGUgc2h1ZmZsZSBvcGVyYXRpb24gbWF5IHRoZW4gYmUgcmVwZWF0ZWQgdG8gZm9ybSBhIG5ldyA8c3Ryb25nPlM8c3ViPjEyPC9zdWI+PC9zdHJvbmc+LjwvcD4KPHA+Rm9yIHRoaXMgcHJvYmxlbSwgeW91IHdpbGwgd3JpdGUgYSBwcm9ncmFtIHRvIGRldGVybWluZSBpZiBhIHBhcnRpY3VsYXIgcmVzdWx0YW50IHN0YWNrIDxzdHJvbmc+UzxzdWI+MTI8L3N1Yj48L3N0cm9uZz4gY2FuIGJlIGZvcm1lZCBieSBzaHVmZmxpbmcgdHdvIHN0YWNrcyBzb21lIG51bWJlciBvZiB0aW1lcy48L3A+Cgo8cCBjbGFzcz0="pst">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 S1and 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

Greater New York 2006 一道模拟题, 解题思路:这个直接模拟(或者退化的BFS或DFS吧,就一种情况,汗。~)题目所要求的Shuffle的过程就行了,只是要注意搜索失败的条件。当S1和S2又回到初始化状态时就是搜索失败的条件,为什么会这样呢?把所有的情况放在一个集合里面,Shuffle会模拟到所有情况,直到回到初始状态,无限循环下去。
代码:

#include #include #include #include #include using namespace std; #define M 110 char mat[220],S1[M],S2[M]; char map[1000][220]; int main() { int n,m,i,j,x,k; while(scanf("%d",&m)!=EOF&&m) { for(k=1;k

点击复制链接 与好友分享!回本站首页
您对本文章有什么意见或着疑问吗?请到论坛讨论您的关注和建议是我们前行的参考和动力
上一篇:ZOJ3156_Taxi(二分图/二分构图)
下一篇:CF #261 Div2 D. Pashmak and Parmida's problem (离散化+逆序对+线段树)
相关文章

POJ3621最优比率生成环 01分数规划问题

poj 1928

poj 3728 tarjan+带权路径并查集

poj 3321

POJ 1664 放苹果 递推

poj 1631

poj模拟题总结(一)

POJ 1083

POJ 1952 BUY LOW, BUY LOWER

poj 1195

图文推荐

POJ 3087 Shuffle'm Up (模拟)
ZOJ 3640 Help Me
POJ 3087 Shuffle'm Up (模拟)
CF 518C(Anya and
POJ 3087 Shuffle'm Up (模拟)
hdu 1016 Prime R
UVA - 11987 - A

分类:默认分类 时间:2015-03-02 人气:3
本文关键词:
分享到:

相关文章

Copyright (C) quwantang.com, All Rights Reserved.

趣玩堂 版权所有 京ICP备15002868号

processed in 0.682 (s). 10 q(s)