poj3087 Shuffle'm Up(bfs)
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)的更多相关文章
- POJ3087:Shuffle'm Up(模拟)
http://poj.org/problem?id=3087 Description A common pastime for poker players at a poker table is to ...
- POJ 3087 Shuffle'm Up bfs
题目链接:Shuffle'm Up 除了英文题有点恶心.发现模拟 + bfs 就可以过的时候,就是水了. 一个bug 就是filp函数得到string s12失败了.恩.据大腿告知,string 并不 ...
- poj3087 Shuffle'm Up(模拟)
Shuffle'm Up Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 10766 Accepted: 4976 Des ...
- POJ-3087 Shuffle'm Up (模拟)
Description A common pastime for poker players at a poker table is to shuffle stacks of chips. Shuff ...
- POJ3087 Shuffle'm Up —— 打表找规律 / map判重
题目链接:http://poj.org/problem?id=3087 Shuffle'm Up Time Limit: 1000MS Memory Limit: 65536K Total Sub ...
- poj3087 Shuffle'm Up
Description A common pastime for poker players at a poker table is to shuffle stacks of chips. Shuff ...
- POJ3087 Shuffle'm Up 简单模拟
题意:就是给你两副扑克,然后一张盖一张洗牌,不断重复这个过程,看能不能达到目标的扑克顺序 分析:然后就模拟下,-1的情况就是有循环节 #include<cstdio> #include&l ...
- POJ3087 Shuffle'm Up(模拟)
题目链接. AC代码如下; #include <iostream> #include <cstdio> #include <cstring> #include &l ...
- POJ3087 Shuffle'm Up
题目: 现有字符串s1.s2.s12,其中s1.s2的长度为len,s12的长度为2*len. 是否可以通过一些操作使s1和s2转换合并成s12? 变换的操作规则如下: 假设s1=11111,s2=0 ...
随机推荐
- 用webstorm搭建vue项目
本文只针对新手. 首先要明白几个名词(概念). Node.js: Node.js 是一个基于 Chrome V8 引擎的 JavaScript 运行环境. Node.js 使用了一个事件驱动.非阻塞式 ...
- OAuth2:客户端证书授权(Client Credentials)类型的开放授权
适应范围 认证服务器不提供像用户数据这样的重要资源,仅仅是有限的只读资源或者一些开放的API.例如使用了第三方的静态文件服务,如Google Storage或Amazon S3.这样,你的应用需要通过 ...
- Python 输出有颜色的字体
https://www.cnblogs.com/hellojesson/p/5961570.html
- Codeforces Round #517 体验记
原文链接 https://www.cnblogs.com/zhouzhendong/p/CF1071.html 赛前: 呀,这个 Round # 必须打啊. 于是临时改变注意决定打这一场.用小号打. ...
- Python dictionary 字典 常用法
Python dictionary 字典 常用法 d = {} d.has_key(key_in) # if has the key of key_in d.keys() ...
- Maze-hdu4035(DP求概率)
链接:http://acm.hdu.edu.cn/showproblem.php?pid=4035 题意: 有n个房间,由n-1条隧道连通起来,实际上就形成了一棵树, 从结点1出发,开始走,在每个结点 ...
- ELM:ELM基于近红外光谱的汽油测试集辛烷值含量预测结果对比—Jason niu
%ELM:ELM基于近红外光谱的汽油测试集辛烷值含量预测结果对比—Jason niu load spectra_data.mat temp = randperm(size(NIR,1)); P_tra ...
- RabbitMQ实战经验分享
前言 最近在忙一个高考项目,看着系统顺利完成了这次高考,终于可以松口气了.看到那些即将参加高考的学生,也想起当年高三的自己. 下面分享下RabbitMQ实战经验,希望对大家有所帮助: 一.生产消息 关 ...
- SQL 分隔字符串
ALTER FUNCTION dbo.fn_Split ( ), ) ) RETURNS @table_Value TABLE ( SortNo ,) NOT NULL, Value ) COLLAT ...
- Oracle DB
索引 一.安装 卸载 一.安装 1.Oracle首先询问用户是否接受更新信息,一般选择不接受:Oracle安装选项,需为其配置数据库,所以此处会询问是否创建安装数据库,选择是系统类型,一般选择服务 ...