//716K 0MS G++#include <cstdio>#include <string>#include <map>#include <iostream>using namespace std;map<string, int> stackMap;int stackLength;string S1;string S2;string S12;string res;void interleave() { S12 = ""; for (int i = 0; i < stackLength; i++) { S12 += S2[i]; S12 += S1[i]; } S1 = S12.substr(0, stackLength); S2 = S12.substr(stackLength, stackLength);}int solve() { stackMap.clear(); int stepNum = 0; while(1) { interleave(); stepNum++; if (S12 == res) { return stepNum; } else { if (stackMap.find(S12) != stackMap.end()) { // cout<<S12; return -1; } else { stackMap.insert(pair<string, int>(S12, 1)); // cout<<" I "<<S12; } } }}int main() { int caseNum; scanf("%d", &caseNum); for (int i = 1; i <= caseNum; i++) { scanf("%d", &stackLength); cin>>S1; cin>>S2; cin>>res; printf("%d %d\n", i, solve()); }}
估计问题类别是错误的,不是搜索问题,每次固定只有一个选择,赢也可以被认为是图片。
但是,调查的重点应该是hash的重复判断 以及字符串的操作。
懒得再做了,直接STL map 和 string, 其实是水题,但是2b看错了题,忘了清空map, 还WA了2次.