Shuffle'm Up poj 3087
2015-02-06 23:08
387 查看
/*********************************************** * Author: fisty * Created Time: 2015/2/6 16:43:28 * File Name : 1_G.cpp *********************************************** */ #include <iostream> #include <cstring> #include <deque> #include <cmath> #include <queue> #include <stack> #include <list> #include <map> #include <set> #include <string> #include <vector> #include <cstdio> #include <bitset> #include <algorithm> using namespace std; #define Debug(x) cout << #x << " " << x <<endl #define Memset(x, a) memset(x, a, sizeof(x)) const int INF = 0x3f3f3f3f; typedef long long LL; typedef pair<int, int> P; #define FOR(i, c, d) for(int i = c;i < d; i++) #define MAX_N 1010 string c; map<string, int> hash; int vis[MAX_N][MAX_N]; int n,ok, ans, cnt; void dfs(string a, string b, int res){ if(!hash.count(a)) hash[a] = cnt++; if(!hash.count(b)) hash[b] = cnt++; if(vis[hash[a]][hash[b]]) return ; vis[hash[a]][hash[b]] = 1; string s; s.clear(); FOR(i, 0, n){ s.push_back(b[i]); s.push_back(a[i]); } if(s == c){ if(res < ans){ ans = res; } ok = 1; return ; } a.clear(); b.clear(); FOR(i, 0, n){ a.push_back(s[i]); } FOR(i, n, n*2){ b.push_back(s[i]); } dfs(a, b, res+1); return ; } int main() { //freopen("in.cpp", "r", stdin); cin.tie(0); ios::sync_with_stdio(false); int t; cin >> t; int kcase = 1; while(t--){ cout << kcase++ << " "; string a, b; cin >> n >> a >> b >> c; memset(vis, 0, sizeof(vis)); ok = 0; ans = INF; cnt = 0; dfs(a, b, 1); if(ok){ cout << ans << endl; }else{ cout << -1 << endl; } } return 0; }
相关文章推荐
- POJ 3087 Shuffle'm Up (模拟)
- POJ 3087 Shuffle'm Up(....)
- G - Shuffle'm Up POJ 3087 模拟洗牌的过程,算作暴力搜索也不为过
- POJ 3087 Shuffle'm Up
- poj 3087 Shuffle'm Up
- POJ_3087_Shuffle'm Up
- POJ 3087 Shuffle'm Up (模拟)
- Poj 3087 Shuffle'm Up 【BFS】
- poj 3087 Shuffle'm Up
- poj 3087 Shuffle'm Up(bfs)
- POJ 3087 Shuffle'm Up(模拟退火)
- POJ 3087 Shuffle'm Up(kuangbin带你飞 专题一:简单搜索)专题一完结
- poj 3087 Shuffle'm Up(模拟题)
- 模拟-POJ-3087-Shuffle'm up
- POJ 3087 Shuffle'm Up
- poj 3087 Shuffle'm Up (模拟搜索)
- POJ-3087 Shuffle'm Up 解题报告(陈小宾)
- POJ 3087 Shuffle'm Up - 模拟
- poj 3087 Shuffle'm Up
- poj-3087-Shuffle'm Up-模拟