亚洲香蕉成人av网站在线观看_欧美精品成人91久久久久久久_久久久久久久久久久亚洲_热久久视久久精品18亚洲精品_国产精自产拍久久久久久_亚洲色图国产精品_91精品国产网站_中文字幕欧美日韩精品_国产精品久久久久久亚洲调教_国产精品久久一区_性夜试看影院91社区_97在线观看视频国产_68精品久久久久久欧美_欧美精品在线观看_国产精品一区二区久久精品_欧美老女人bb

首頁 > 學院 > 開發設計 > 正文

poj3087——Shuffle'm Up(BFS)

2019-11-10 17:49:25
字體:
來源:轉載
供稿:網友

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 S2 and 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

題目其實很簡單,模擬切牌的過程,兩堆牌s1,s2組合成s12,s1的第一張牌在最頂上。然后再從s12的底部開始,取一半成s1,另一半就是s2,再次組合直到順序和題目中給出的一樣。 模擬一下就好。

#include <iostream>#include <cstring>#include <string>#include <vector>#include <queue>#include <cstdio>#include <set>#include <map>#include <cmath>#include <algorithm>#define INF 0x3f3f3f3f#define MAXN 100005#define Mod 10001using namespace std;string s1,s2,ans;int c;map<string,int> step;string shuffle(string a,string b){ string s12; for(int i=0;i<c;++i) { s12+=b[i]; s12+=a[i]; } return s12;}int bfs(){ string s12=shuffle(s1,s2); queue<string> q; q.push(s12); step[s12]=1; while(!q.empty()) { string tmp=q.front(); q.pop(); if(tmp==ans) return step[tmp]; s1=tmp.substr(0,c); s2=tmp.substr(c,c); s12=shuffle(s1,s2); if(step[s12]>0) return -1; step[s12]=step[tmp]+1; q.push(s12); }}int main(){ int t; scanf("%d",&t); for(int cas=1;cas<=t;++cas) { scanf("%d",&c); cin>>s1>>s2>>ans; printf("%d %d/n",cas,bfs()); } return 0;}
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
亚洲香蕉成人av网站在线观看_欧美精品成人91久久久久久久_久久久久久久久久久亚洲_热久久视久久精品18亚洲精品_国产精自产拍久久久久久_亚洲色图国产精品_91精品国产网站_中文字幕欧美日韩精品_国产精品久久久久久亚洲调教_国产精品久久一区_性夜试看影院91社区_97在线观看视频国产_68精品久久久久久欧美_欧美精品在线观看_国产精品一区二区久久精品_欧美老女人bb
黄色一区二区在线| 国产99视频精品免视看7| 欧美在线中文字幕| 精品精品国产国产自在线| 亚洲精品日韩丝袜精品| 欧美成人午夜激情在线| 俺也去精品视频在线观看| 91精品国产自产在线| 国产欧美在线观看| 精品中文字幕在线2019| 成人中心免费视频| 国模吧一区二区三区| 庆余年2免费日韩剧观看大牛| 日韩精品电影网| 国产精品美女久久久久久免费| 日韩在线观看视频免费| 黑人精品xxx一区| 欧美一级片免费在线| 中文字幕九色91在线| 亚洲国产精品视频在线观看| 国产精品亚洲一区二区三区| 国产精品ⅴa在线观看h| 久久精品亚洲一区| 久久精品夜夜夜夜夜久久| 欧美午夜女人视频在线| 国产精品一区二区三区毛片淫片| 欧美日韩在线看| 欧美激情欧美激情| 亚洲视频电影图片偷拍一区| 久久中文久久字幕| 欧美孕妇孕交黑巨大网站| 欧美激情精品久久久久久久变态| 国产精自产拍久久久久久蜜| 日韩欧美一区二区在线| 日韩av免费一区| 奇米成人av国产一区二区三区| 国产精品亚洲视频在线观看| 国产成人亚洲综合青青| 欧美激情精品久久久久久变态| 久久免费视频在线| 国产成人avxxxxx在线看| 欧美性猛交xxxx黑人猛交| 国产精品美女免费看| 欧美黑人xxx| 欧美电影免费观看电视剧大全| 亚洲国产古装精品网站| 欧美日韩午夜剧场| 国产亚洲aⅴaaaaaa毛片| 国产精品视频午夜| 最好看的2019的中文字幕视频| 欧美性69xxxx肥| 91av在线播放| 欧美理论片在线观看| 日韩精品在线免费播放| 亚洲欧美日韩视频一区| 午夜精品视频在线| 中文字幕久精品免费视频| 一区二区三区回区在观看免费视频| 国产精品青草久久久久福利99| 久久99精品视频一区97| 精品视频在线播放免| 国产精品一区专区欧美日韩| 456亚洲影院| 91天堂在线视频| 国产精品黄视频| 日韩欧美在线看| 国产精选久久久久久| 日本欧美一二三区| 亚洲一区二区精品| 国产激情久久久久| 亚洲国产成人久久综合一区| 成人乱人伦精品视频在线观看| 欧美日韩国产区| 国产精品女人久久久久久| 神马国产精品影院av| 91精品视频专区| 97免费视频在线| 久久影视免费观看| 欧美日韩亚洲精品一区二区三区| 日本亚洲欧美成人| 国产精品高清网站| 久久精品视频免费播放| 日韩欧美精品免费在线| 色婷婷**av毛片一区| 97视频在线播放| 亚洲综合社区网| 国产一区二区丝袜高跟鞋图片| 午夜精品福利电影| 国产精品日韩欧美| 国产精品女人久久久久久| 日韩免费在线电影| 亚洲天堂免费视频| 国产成人久久久| 国产一区欧美二区三区| 国产中文字幕亚洲| 国产999视频| 亚洲美女在线看| 91高清在线免费观看| 亚洲欧洲在线观看| 欧美日韩ab片| 久久久久久国产精品久久| 国产精品成人av在线| 麻豆乱码国产一区二区三区| 韩国欧美亚洲国产| 91成品人片a无限观看| 91久久中文字幕| 欧美日韩亚洲一区二区三区| 91精品免费视频| 欧美日韩免费在线观看| 中文字幕在线成人| 亚洲欧美日本伦理| 一本色道久久综合亚洲精品小说| 欧美成人一二三| 国产精品视频网址| 一区二区欧美亚洲| 国产精品三级久久久久久电影| 欧美午夜www高清视频| 日韩高清不卡av| 亚洲福利视频在线| 日韩福利伦理影院免费| 亚洲电影成人av99爱色| 97婷婷涩涩精品一区| 懂色aⅴ精品一区二区三区蜜月| 欧美日韩中文字幕在线视频| 91av在线不卡| 国产噜噜噜噜久久久久久久久| 91欧美激情另类亚洲| 96sao精品视频在线观看| 亚洲欧美成人网| 日本精品视频在线观看| 色久欧美在线视频观看| 中日韩午夜理伦电影免费| 国产精品入口免费视频一| 欧美国产日韩视频| 成人精品在线视频| 夜夜嗨av色综合久久久综合网| 成人黄色免费网站在线观看| 91大神福利视频在线| 国产精品99久久99久久久二8| 国产啪精品视频网站| 国产精品久久久久久久久久东京| 国产精品高潮呻吟久久av野狼| 国产精品视频xxx| 日韩美女在线观看一区| 午夜精品一区二区三区av| 中文字幕亚洲第一| 黑人巨大精品欧美一区二区免费| 国产精品ⅴa在线观看h| 亚洲精品www久久久久久广东| 日韩亚洲欧美成人| 91沈先生在线观看| 91最新国产视频| 亚洲va久久久噜噜噜| 俺去亚洲欧洲欧美日韩| 狠狠躁夜夜躁人人躁婷婷91| 亚洲图片在线综合| 国产精品视频色| 国产精品日韩电影| 成人精品网站在线观看| 亚洲97在线观看| 欧美性猛交xxxx偷拍洗澡| 上原亚衣av一区二区三区| 97国产精品视频人人做人人爱| 久久久综合av|