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

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

poj3087——Shuffle'm Up(BFS)

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

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
日韩成人av在线播放| 日本乱人伦a精品| 日韩在线观看电影| 伦伦影院午夜日韩欧美限制| 色婷婷综合久久久久中文字幕1| 久久亚洲精品国产亚洲老地址| 国产精品影片在线观看| 日韩电影在线观看中文字幕| 狠狠躁夜夜躁人人爽天天天天97| 色噜噜国产精品视频一区二区| 成人黄色av免费在线观看| 国产精品美女视频网站| 亚洲欧美激情另类校园| 久久免费观看视频| 欧美成人免费一级人片100| 在线视频亚洲欧美| 欧美激情视频网| 欧美人成在线视频| 欧美一级大片在线观看| 欧美在线激情视频| 亚洲天堂av高清| 日韩中文字幕在线播放| 亚洲一区二区久久久| 国产成+人+综合+亚洲欧洲| 亚洲欧美日韩一区二区在线| 91tv亚洲精品香蕉国产一区7ujn| 美女福利精品视频| 韩剧1988在线观看免费完整版| 日韩成人在线观看| 国产精品入口免费视频一| 久久福利网址导航| 日本精品视频在线播放| 日韩欧美有码在线| www.国产一区| 91精品国产乱码久久久久久蜜臀| 欧美日韩国产123| 久久免费视频在线观看| 亚洲美女动态图120秒| 久久免费观看视频| 欧美日韩亚洲天堂| 亚洲精品电影在线观看| 456亚洲影院| 成人免费在线视频网站| 秋霞成人午夜鲁丝一区二区三区| 91精品在线一区| 欧美日韩国产色视频| 国产精品手机播放| 欧美怡春院一区二区三区| 欧美乱大交xxxxx| 中文字幕国产亚洲2019| 国产一区二区三区毛片| 91精品视频在线免费观看| 91香蕉嫩草神马影院在线观看| 欧美一乱一性一交一视频| 日韩精品欧美激情| 日韩精品极品毛片系列视频| 国产欧美亚洲视频| 欧美性猛交xxxx免费看| 亚洲肉体裸体xxxx137| 亚洲自拍偷拍网址| 少妇高潮 亚洲精品| 亚洲国产中文字幕久久网| 亚洲一级片在线看| 中文字幕精品影院| 亚洲片国产一区一级在线观看| 岛国av一区二区在线在线观看| 日韩av一区在线观看| 免费91麻豆精品国产自产在线观看| 久久久国产一区二区| 亚洲高清免费观看高清完整版| 91免费看国产| 国产成人精品日本亚洲专区61| 中文字幕日韩欧美在线视频| 国产精品亚洲第一区| 国产精品久久久久久久久久久新郎| 中文字幕精品视频| 国产亚洲欧美一区| 日韩成人在线视频观看| 成人在线免费观看视视频| 激情懂色av一区av二区av| 成人性生交大片免费看视频直播| 高清一区二区三区四区五区| 亚洲xxxx做受欧美| 美女少妇精品视频| 久久久精品欧美| 91精品啪在线观看麻豆免费| 精品亚洲一区二区三区在线播放| 亚洲精品久久久一区二区三区| 日韩美女免费线视频| 亚洲国产精品99| 久久久久久成人精品| 国产精品第一页在线| 亚洲免费高清视频| 亚洲成人av片在线观看| 久久久噜久噜久久综合| 尤物99国产成人精品视频| 色哟哟亚洲精品一区二区| 国产精品视频地址| 欧美高清第一页| 日韩精品福利网站| 亚洲精品美女久久| 日本伊人精品一区二区三区介绍| 国产97人人超碰caoprom| 国产精品成人一区二区| 国产精品大陆在线观看| 亚洲精品免费网站| 亚洲国产精品人人爽夜夜爽| 亚洲人成电影在线| 欧美激情精品久久久久久久变态| 久久久国产精品x99av| 琪琪第一精品导航| 欧美电影免费在线观看| 亚洲美女精品久久| 精品一区二区亚洲| 日韩精品中文字| 亚洲成人精品久久久| 日韩一级裸体免费视频| 欧美高清理论片| 国产91|九色| 亚洲乱码一区av黑人高潮| 欧美日韩亚洲一区二区| 日韩在线高清视频| 国产91精品视频在线观看| 精品久久久久久中文字幕大豆网| 97在线免费视频| 国产精品热视频| 日韩av一区二区在线| 91精品免费视频| 91超碰caoporn97人人| 国产精品大片wwwwww| 久久天天躁狠狠躁夜夜av| 91精品久久久久久久久久久久久| 欧美一乱一性一交一视频| 欧美与黑人午夜性猛交久久久| 这里只有精品在线播放| 亚洲自拍偷拍第一页| 久久久久久伊人| 亚洲女同精品视频| 久久久在线观看| 精品视频一区在线视频| 久久精品国产亚洲7777| 亚洲福利在线播放| 色婷婷**av毛片一区| 国产精品极品尤物在线观看| 性欧美xxxx视频在线观看| 亚洲人成亚洲人成在线观看| 成人在线中文字幕| 欧美日韩在线视频一区二区| 中文字幕免费精品一区高清| 成人免费视频xnxx.com| 亚洲欧美激情一区| 国产精品福利在线观看| 欧美日韩高清在线观看| 亚洲欧洲日产国码av系列天堂| 色妞色视频一区二区三区四区| 亚洲欧洲美洲在线综合| 大桥未久av一区二区三区| 欧美激情2020午夜免费观看| 性色av一区二区三区红粉影视| 日韩精品免费在线观看| www.欧美精品一二三区| 中文字幕免费精品一区高清| 欧美日韩一区二区在线播放| 亚洲国产另类久久精品|