http://poj.org/problem?id=3087

注意复制字符串的时候,要在末尾加上'\0',否则导致strcmp出错。

还有就是开数组大小的时候看清楚一点,别开错了debug了好久。

 #include<iostream>
#include<cstdio>
#include<queue>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<set>
#define IO ios::sync_with_stdio(false);cin.tie(0);
#define INF 0x3f3f3f3f3f3f3f3f
typedef long long ll;
using namespace std;
int t, n, k, kase=;
char s12[], s1[], s2[];
char vis[][];
typedef struct{
int cnt;
char s[];
}Node;
int panduan(Node a)
{
if(!strcmp(s12, a.s))
return ;
return ;
}
int panduan2(Node a)
{
for(int i = ; i < k; i++){
if(!strcmp(a.s, vis[i])){
return ;
}
}
return ;
}
void bfs()
{
k=;
int flag=;
Node node;
queue<Node> q;
int j = ;
for(int i = ; i < *n; i += ){
node.s[i] = s2[j++];
}
j = ;
for(int i = ; i < *n; i += ){
node.s[i] = s1[j++];
}
node.s[*n] = '\0';
node.cnt=;
q.push(node);
while(!q.empty()){
Node t = q.front(), p;
strcpy(vis[k++], t.s);
q.pop();
/*for(int i = 0; i < 2*n; i++){
cout << t.s[i];
} cout << endl;*/
if(panduan(t)){
flag=;
cout << ++kase << " " << t.cnt << endl;
break;
}
//拆分
j=;
for(int i = ; i < n; i++){
s1[j++] = t.s[i];
}
j=;
for(int i = n; i < *n; i++){
s2[j++] = t.s[i];
}
//合并
j=;
for(int i = ; i < *n; i += ){
p.s[i] = s2[j++];
}
j = ;
for(int i = ; i < *n; i += ){
p.s[i] = s1[j++];
}
p.s[*n] = '\0';
p.cnt=t.cnt+;
if(panduan2(p)){
//strcpy(vis[k++], p.s);
q.push(p);
}
}
if(!flag){
cout << ++kase << " " << "-1" << endl;
}
}
int main()
{
cin >> t;
while(t--){
cin >> n;
cin >> s1 >> s2 >> s12;
memset(vis, , sizeof(vis));
//cout << ++kase << " ";
bfs();
}
return ;
}

poj3087 Shuffle'm Up(bfs)的更多相关文章

  1. POJ3087:Shuffle'm Up(模拟)

    http://poj.org/problem?id=3087 Description A common pastime for poker players at a poker table is to ...

  2. POJ 3087 Shuffle'm Up bfs

    题目链接:Shuffle'm Up 除了英文题有点恶心.发现模拟 + bfs 就可以过的时候,就是水了. 一个bug 就是filp函数得到string s12失败了.恩.据大腿告知,string 并不 ...

  3. poj3087 Shuffle'm Up(模拟)

    Shuffle'm Up Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 10766   Accepted: 4976 Des ...

  4. POJ-3087 Shuffle'm Up (模拟)

    Description A common pastime for poker players at a poker table is to shuffle stacks of chips. Shuff ...

  5. POJ3087 Shuffle'm Up —— 打表找规律 / map判重

    题目链接:http://poj.org/problem?id=3087 Shuffle'm Up Time Limit: 1000MS   Memory Limit: 65536K Total Sub ...

  6. poj3087 Shuffle'm Up

    Description A common pastime for poker players at a poker table is to shuffle stacks of chips. Shuff ...

  7. POJ3087 Shuffle'm Up 简单模拟

    题意:就是给你两副扑克,然后一张盖一张洗牌,不断重复这个过程,看能不能达到目标的扑克顺序 分析:然后就模拟下,-1的情况就是有循环节 #include<cstdio> #include&l ...

  8. POJ3087 Shuffle'm Up(模拟)

    题目链接. AC代码如下; #include <iostream> #include <cstdio> #include <cstring> #include &l ...

  9. POJ3087 Shuffle'm Up

    题目: 现有字符串s1.s2.s12,其中s1.s2的长度为len,s12的长度为2*len. 是否可以通过一些操作使s1和s2转换合并成s12? 变换的操作规则如下: 假设s1=11111,s2=0 ...

随机推荐

  1. Javascript \x 反斜杠x 16进制 编解码

    js 里 \x 开头的通常是16进制编码的数据,下面代码实现编解码: 解码 function decode(str){ return str.replace(/\\x(\w{2})/g,functio ...

  2. 修改element ui 默认样式最好的解释

    KedAyAyA 17年10月 https://forum.vuejs.org/t/elementui/19171/5 首先添加了scoped的style标签会在vue-loader里进行处理 所谓的 ...

  3. Codeforces 868F Yet Another Minimization Problem 决策单调性 (看题解)

    Yet Another Minimization Problem dp方程我们很容易能得出, f[ i ] = min(g[ j ] + w( j + 1, i )). 然后感觉就根本不能优化. 然后 ...

  4. React 入门实例教程(转载)

    现在最热门的前端框架,毫无疑问是 React . 上周,基于 React 的 React Native 发布,结果一天之内,就获得了 5000 颗星,受瞩目程度可见一斑. React 起源于 Face ...

  5. Codeforces 542E Playing on Graph 其他

    原文链接https://www.cnblogs.com/zhouzhendong/p/CF542E.html 题目传送门 - CF542E 题目传送门 - 51Nod1481 题意 有一幅无向图,它有 ...

  6. Codeforces 1071C Triple Flips 构造

    原文链接 https://www.cnblogs.com/zhouzhendong/p/CF1071C.html 题目传送门 - CF1071C 题意 给定一个长度为 n 的 01 数列,限定你在 $ ...

  7. BZOJ4811 [Ynoi2017]由乃的OJ 树链剖分

    原文链接http://www.cnblogs.com/zhouzhendong/p/8085286.html 题目传送门 - BZOJ4811 题意概括 是BZOJ3668长在树上并加上修改和区间询问 ...

  8. Ubuntu 硬盘分区只读,重新挂载为读写分区之后,文件依然创建出错

    原因: 分区只读,可能是windows没有正常关机,或者使用了混合休眠模式. 解决方案: sudo mount -o remount,rw /dev/sdaX 若重新挂载后,创建文件以及文件夹失败: ...

  9. CNN:人工智能之神经网络算法进阶优化,六种不同优化算法实现手写数字识别逐步提高,应用案例自动驾驶之捕捉并识别周围车牌号—Jason niu

    import mnist_loader from network3 import Network from network3 import ConvPoolLayer, FullyConnectedL ...

  10. ubantu 14.04中安装npm+node.js+react antd

    今天折腾了半天,各种安装问题,最终还是装上了: 1.安装npm $ sudo apt install npm 2.升级npm $ sudo npm install npm@latest -g 输入np ...