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. Asp.Net MVC及Web API框架配置会碰到的几个问题及解决方案 (精髓)

    前言 刚开始创建MVC与Web API的混合项目时,碰到好多问题,今天拿出来跟大家一起分享下.有朋友私信我问项目的分层及文件夹结构在我的第一篇博客中没说清楚,那么接下来我就准备从这些文件怎么分文件夹说 ...

  2. windows server远程连接提示“终端服务器超出了最大允许连接”

  3. Jenkins.war包构建Jenkins平台

    [root@jenkins ~]# wget -O /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-7.repo [roo ...

  4. Codeforces 639D Bear and Contribution

    Bear and Contribution 对于对于5余数为, 0, 1, 2, 3, 4的分别处理一次, 用优先队列贪心. #include<bits/stdc++.h> #define ...

  5. PAT (Basic Level) Practise - 写出这个数

    题目链接:https://www.patest.cn/contests/pat-b-practise/1002 读入一个自然数n,计算其各位数字之和,用汉语拼音写出和的每一位数字. 输入格式:每个测试 ...

  6. Python isinstance 方法 判断 built-in types(内置类型)技巧

    Python isinstance 方法 判断 built-in types(内置类型)技巧 d = {} isinstance(d, type({})) isinstance(d, dict) l ...

  7. Team Queue POJ - 2259 (队列)

    Queues and Priority Queues are data structures which are known to most computer scientists. The Team ...

  8. C. A Mist of Florescence ----- Codeforces Round #487 (Div. 2)

    C. A Mist of Florescence time limit per test 1 second memory limit per test 256 megabytes input stan ...

  9. Java中对数组的操作

    数组对于每一门编程语言来说都是重要的数据结构之一,当然不同语言对于数组的实现及处理也不尽相同. Java语言中提供的数组是用来存储固定大小的同类型元素.如:声明一个数组变量,numbers[100]来 ...

  10. elf 学习

    现在我们使用 readelf 命令来查看 elfDome.out 的文件头 readelf -l elfDemo.out 使用 readelf 来查看程序头: readelf -S elfDemo.o ...