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

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

poj3087——Shuffle'm Up(BFS)

2019-11-10 18:00:34
字體:
來源:轉載
供稿:網友

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
久久成人免费视频| 最近2019中文字幕在线高清| 欧美在线观看网址综合| 福利视频第一区| 日韩欧美在线播放| 久久久极品av| 久久精品人人爽| 亚洲人在线观看| 精品久久久在线观看| 亚洲国产成人久久综合一区| 久久久这里只有精品视频| 91久热免费在线视频| 性亚洲最疯狂xxxx高清| 日韩一级裸体免费视频| 日韩有码在线播放| 成人黄色av网| 欧洲成人在线观看| 国产综合福利在线| 亚洲自拍av在线| 91精品国产高清自在线看超| 狠狠色狠色综合曰曰| 日韩av一区二区在线| 国产亚洲aⅴaaaaaa毛片| 26uuu亚洲伊人春色| 国产精品视频999| 一本色道久久88精品综合| 欧美激情欧美激情| 国产在线98福利播放视频| 在线观看欧美日韩国产| 日韩av电影在线播放| 久久久国产一区二区| 欧美性生活大片免费观看网址| 国产精品美女久久久久av超清| 日产日韩在线亚洲欧美| 亚洲成人国产精品| 亚洲男人第一av网站| 亚洲精品国产精品乱码不99按摩| 在线观看成人黄色| 欧美精品久久久久久久| 欧美三级欧美成人高清www| 国产自产女人91一区在线观看| 亚洲欧美精品一区二区| 欧美精品免费播放| 亚洲最大av在线| 日韩中文字幕网址| 69久久夜色精品国产7777| 欧美一级高清免费| 亚洲国产高清自拍| 久久亚洲国产成人| 国产在线精品成人一区二区三区| 欧美亚洲在线观看| 久久久久中文字幕| 操日韩av在线电影| 亚洲专区中文字幕| 国产一区二区丝袜| 欧美日韩中文在线| 国产美女搞久久| 欧美黄网免费在线观看| 尤物精品国产第一福利三区| 久久免费国产精品1| 欧亚精品中文字幕| 亚洲精品自产拍| 亚洲国产精品专区久久| 欧美高清理论片| 97视频在线观看免费| 欧美激情区在线播放| 91精品国产99| 亚洲欧美中文字幕| 91探花福利精品国产自产在线| 亚洲女人被黑人巨大进入al| 一本久久综合亚洲鲁鲁| 亚洲欧美成人网| 日韩在线免费视频| 亚洲第一精品福利| 国产一区二区三区视频在线观看| 91国内揄拍国内精品对白| 亚洲自拍另类欧美丝袜| 久久av资源网站| 久久久精品999| 66m—66摸成人免费视频| 欧美激情精品久久久久久免费印度| 91精品在线一区| 久久国产精品亚洲| 欧美黑人xxxⅹ高潮交| 夜夜躁日日躁狠狠久久88av| 亚洲欧洲激情在线| 亚洲欧美日韩国产精品| 欧美日韩在线一区| 久久国产加勒比精品无码| 高清欧美一区二区三区| 一本大道香蕉久在线播放29| 中文字幕最新精品| 亚洲欧美国产制服动漫| 亚洲一区www| 91精品国产沙发| 亚洲一区亚洲二区亚洲三区| 国产性猛交xxxx免费看久久| 欧美日韩在线视频观看| 国产欧美一区二区三区视频| 亚洲欧美国产va在线影院| 精品国产欧美成人夜夜嗨| 中文字幕自拍vr一区二区三区| 国产精品久久二区| 97精品伊人久久久大香线蕉| 美日韩精品免费观看视频| 在线观看日韩www视频免费| 日韩视频在线观看免费| 国产欧美va欧美va香蕉在线| 欧美丝袜一区二区三区| 日韩va亚洲va欧洲va国产| 日韩av成人在线| 国产精品黄视频| 热门国产精品亚洲第一区在线| 黄网站色欧美视频| 日韩亚洲精品视频| 国产精品视频中文字幕91| www.久久久久久.com| 亚洲精品永久免费| 成人网在线免费观看| 中日韩午夜理伦电影免费| 91久久久久久久久久久久久| 久久国产精品久久久久久久久久| 午夜欧美不卡精品aaaaa| 久久久久久久久久久网站| 欧美日韩国产一区在线| 国产亚洲免费的视频看| 精品成人国产在线观看男人呻吟| 亚洲欧美中文字幕在线一区| 欧洲精品久久久| 久久久久一本一区二区青青蜜月| 38少妇精品导航| 亚洲综合日韩中文字幕v在线| 亚洲片av在线| 色综合久久天天综线观看| 福利精品视频在线| 亚洲欧美日韩国产中文专区| 欧美成人精品在线观看| 国产日韩av在线| 久久久国产视频91| 国产美女久久精品| 亚洲精品综合久久中文字幕| 国产精品亚洲欧美导航| 97超级碰碰碰| 亚洲精品狠狠操| 日韩av中文在线| 国产精品99久久久久久www| 91高潮在线观看| 成人免费xxxxx在线观看| xxav国产精品美女主播| 久久久久久综合网天天| 欧美影院成年免费版| 欧美日韩免费区域视频在线观看| 1769国内精品视频在线播放| 亚洲综合精品一区二区| 欧美日韩午夜剧场| 国产精品日韩在线播放| 日韩精品中文字幕在线观看| 国产成人免费av电影| 91在线高清免费观看| 国产精品美女久久久免费| 国产精品久久91| 7777精品久久久久久| 国内精品一区二区三区| 国产成人av在线|