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

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

poj3087——Shuffle'm Up(BFS)

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

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
51精品国产黑色丝袜高跟鞋| 亚洲精品福利在线| www.久久久久| 国产丝袜一区二区| 欧美精品激情在线观看| 久久99精品视频一区97| 午夜精品在线视频| 亚洲欧洲日产国产网站| 日本视频久久久| 亚洲伦理中文字幕| 亚洲成人激情小说| 久久成人免费视频| 91av视频在线| 国产精品久久久久aaaa九色| 国产免费久久av| 欧美精品在线观看91| 51久久精品夜色国产麻豆| 久久免费成人精品视频| 中文字幕在线亚洲| 日韩国产欧美精品一区二区三区| 亚洲国语精品自产拍在线观看| 国产亚洲精品成人av久久ww| 国产91精品最新在线播放| 欧美精品久久久久久久免费观看| 亚洲成色999久久网站| 欧美午夜www高清视频| 97香蕉超级碰碰久久免费软件| 精品一区二区三区四区在线| 欧美夫妻性生活视频| 欧美电影《睫毛膏》| 亚洲国产精品久久久久| 成人中心免费视频| 精品五月天久久| 日韩成人小视频| 57pao成人永久免费视频| 欧美国产高跟鞋裸体秀xxxhd| 国产xxx69麻豆国语对白| 在线观看国产成人av片| 日韩欧美亚洲一二三区| 国产91免费看片| 久久全国免费视频| 亚洲女在线观看| 粉嫩老牛aⅴ一区二区三区| 日韩在线欧美在线国产在线| 国产成人精品久久亚洲高清不卡| 国产一区二区三区三区在线观看| 精品网站999www| 日韩在线观看免费高清完整版| 国产精品午夜国产小视频| 日产日韩在线亚洲欧美| 中文字幕精品一区二区精品| 国产视频精品va久久久久久| 日韩欧美成人区| 欧美日本高清一区| 午夜剧场成人观在线视频免费观看| 国产一区二区三区四区福利| 亚洲国产精久久久久久久| 亚洲成人精品久久久| 国产成人精品免高潮费视频| 国产成人在线播放| 欧美一级片一区| 国产日韩精品在线播放| 粗暴蹂躏中文一区二区三区| 欧美不卡视频一区发布| 国产精品久久一区主播| 亚洲国产美女精品久久久久∴| 92国产精品视频| 亚洲第一综合天堂另类专| 欧美精品免费看| 欧美成人高清视频| 欧美激情视频网| 欧美日韩中文在线观看| 久久久极品av| 久久久www成人免费精品| 亚洲欧美国产一本综合首页| 欧美成人激情视频免费观看| 亚洲精品乱码久久久久久金桔影视| 久久视频国产精品免费视频在线| 国产自产女人91一区在线观看| 97精品视频在线播放| 欧美一级在线播放| 日韩一区二区精品视频| 国产欧美一区二区三区视频| 日韩国产激情在线| 国产成人精品综合| 久热国产精品视频| 欧美裸体xxxx极品少妇软件| 日本高清不卡在线| 国产精品爽黄69| 91精品国产高清久久久久久| 国产不卡在线观看| 国产精品久久久精品| 色噜噜国产精品视频一区二区| 欧美激情精品久久久久久免费印度| 日韩免费视频在线观看| 国内精品久久久久久影视8| 亚洲一区二区免费在线| 国产精品视频一| 九九热在线精品视频| 久久成人精品一区二区三区| 国产精品专区h在线观看| 北条麻妃一区二区三区中文字幕| 亚洲网站在线看| 91免费电影网站| 在线亚洲午夜片av大片| 91精品国产91久久久久久| 中文字幕亚洲无线码在线一区| 欧美日韩电影在线观看| 亚洲在线观看视频| 欧美性生活大片免费观看网址| 中文字幕久久久av一区| 久久久国产一区二区三区| 91精品综合久久久久久五月天| 91免费版网站入口| 亚洲精品videossex少妇| 欧美—级高清免费播放| 欧美日韩在线视频一区二区| 97香蕉久久夜色精品国产| 精品国产成人av| 亚洲欧美制服丝袜| 亚州国产精品久久久| 7777精品视频| 97在线视频免费观看| 亚洲iv一区二区三区| 日本一区二区在线播放| 久久人人97超碰精品888| 98精品国产高清在线xxxx天堂| 91亚洲精品一区二区| 97视频在线播放| 黄网动漫久久久| 欧美大全免费观看电视剧大泉洋| 久久人人看视频| 欧美日韩视频免费播放| 岛国av一区二区在线在线观看| 91超碰中文字幕久久精品| 午夜欧美大片免费观看| 日韩av日韩在线观看| 亚洲色图欧美制服丝袜另类第一页| 日韩欧美国产骚| 成人午夜黄色影院| 91网在线免费观看| 亚洲日本欧美日韩高观看| 国产a级全部精品| 国产欧美精品一区二区| 亚洲第一精品夜夜躁人人躁| 亚洲精品福利免费在线观看| 国产精品一区二区三区久久| 成人福利网站在线观看11| 国产精品草莓在线免费观看| 欧美午夜片在线免费观看| 久久成人精品一区二区三区| 高清欧美性猛交xxxx黑人猛交| 精品偷拍各种wc美女嘘嘘| 国语自产偷拍精品视频偷| 国产欧美日韩精品专区| 欧美精品一区二区三区国产精品| 亚洲精品小视频在线观看| 日本韩国欧美精品大片卡二| 国产精品视频播放| 亚洲精品一区av在线播放| 亚洲国产日韩欧美在线动漫| 国产成人一区二| 国产日本欧美一区二区三区在线| 成人亚洲综合色就1024|