模拟洗牌的过程,合并两堆拍的方式:使先取s2,再取s1;分离成两堆的方式:下面C张放到s1,上面C张到s2。当前牌型与第一次相同时,说明不能搜索到答案。

AC代码

#include<cstdio>
#include<cstring>

const int maxn = 100 + 5;
char s1[maxn], s2[maxn], s3[maxn * 2], s4[maxn * 2], vis[maxn * 2];
int c;

void deal(char *a){
	int cur = 0;
	for(int i = 0; i < c; ++i){
		a[cur++] = s2[i];
		a[cur++] = s1[i];
	}
	a[cur] = '\0';
}

void deal(){
	for(int i = 0; i < c; ++i){
		s1[i] = s3[i];
		s2[i] = s3[i + c];
	}
}

int dfs(int cnt){
	deal(s3);
	if(!memcmp(s3, s4, sizeof(s4))) return cnt;
	if(cnt > 1 && !memcmp(s3, vis, sizeof(vis))) return -1;
	deal();
	return dfs(cnt + 1);
}

int main(){
	int T;
	scanf("%d", &T);
	int kase = 1;
	while(T--) {
		scanf("%d", &c);
		scanf("%s%s%s", s1, s2, s4); //s4是目标
		printf("%d ", kase++);
		deal(vis);
		printf("%d\n", dfs(1));
	}
	return 0;
}

如有不当之处欢迎指出!

POJ - 3087 模拟 [kuangbin带你飞]专题一的更多相关文章

  1. POJ - 2251 bfs [kuangbin带你飞]专题一

    立体bfs,共有六个方向: const int dx[] = {0,0,1,-1,0,0}; const int dy[] = {1,-1,0,0,0,0}; const int dz[] = {0, ...

  2. POJ - 3414 bfs [kuangbin带你飞]专题一

    状态搜索,每种状态下面共有六种选择,将搜索到的状态保存即可. d[i][j]表示状态A杯中水i升,B杯中水j升,总状态数量不会超过A杯的容量 * B杯的容量. AC代码 #include<cst ...

  3. POJ - 3279 枚举 [kuangbin带你飞]专题一

    这题很经典啊,以前也遇到过类似的题--计蒜客 硬币翻转. 不过这题不仅要求翻转次数最少,且翻转方案的字典序也要最小. 解法:二进制枚举第一行的翻转方案,然后处理第二行,如果第二行的k列的上一列是黑色, ...

  4. POJ - 3984 bfs [kuangbin带你飞]专题一

    bfs搜索过程中将路径保存下即可. AC代码 #include<cstdio> #include<cstring> #include<algorithm> #inc ...

  5. POJ - 1321 dfs [kuangbin带你飞]专题一

    枚举行和列即可,当前已经放下cnt个棋子,当前已经搜索到第r行,如果 n - r + cnt  < k 直接退出,因为后面无法放下剩下的棋子. AC代码 #include<cstdio&g ...

  6. [kuangbin带你飞]专题1-23题目清单总结

    [kuangbin带你飞]专题1-23 专题一 简单搜索 POJ 1321 棋盘问题POJ 2251 Dungeon MasterPOJ 3278 Catch That CowPOJ 3279 Fli ...

  7. 【算法系列学习三】[kuangbin带你飞]专题二 搜索进阶 之 A-Eight 反向bfs打表和康拓展开

    [kuangbin带你飞]专题二 搜索进阶 之 A-Eight 这是一道经典的八数码问题.首先,简单介绍一下八数码问题: 八数码问题也称为九宫问题.在3×3的棋盘,摆有八个棋子,每个棋子上标有1至8的 ...

  8. [kuangbin带你飞]专题一 简单搜索

            ID Origin Title 454 / 1008 Problem A POJ 1321 棋盘问题   328 / 854 Problem B POJ 2251 Dungeon Ma ...

  9. Catch That Cow POJ - 3278 [kuangbin带你飞]专题一 简单搜索

    Farmer John has been informed of the location of a fugitive cow and wants to catch her immediately. ...

随机推荐

  1. <script>元素在XHTML中的用法

    编写XHTML代码的规则要比编写HTML严格得多,例如如下代码: <script type="text/javascript"> function compare(a, ...

  2. base64_encode与base64_decode

    base64_encode 编辑 本词条缺少名片图,补充相关内容使词条更完整,还能快速升级,赶紧来编辑吧! base64_encode() returns 使用 base64 对 data 进行编码. ...

  3. C# WinForm调用UnityWebPlayer Control控件 <学习笔记1>

    工具 1.三维场景 Unity 5.0.2f1 2.开发环境Microsoft Visual Studio 2010 3.需要使用的控件 UnityWebPlayer Control 出现的问题及解决 ...

  4. Android 使用EventBus发送消息接收消息

    基本使用 自定义一个类 public class LoginEvent { private String code;//是否成功 public LoginEvent(String code) { th ...

  5. The man Command

    The man command is used to format and display the man pages. The man pages are a user manual that is ...

  6. Android图像处理 - 高斯模糊的原理及实现

    欢迎大家前往云+社区,获取更多腾讯海量技术实践干货哦~ 由 天天P图攻城狮 发布在云+社区 作者简介:damonxia(夏正冬),天天P图Android工程师 前言 高斯模糊是图像处理中几乎每个程序员 ...

  7. Vue.js搭建路由报错 router.map is not a function,Cannot read property ‘component’ of undefined

    错误: 解决办法: 2.0已经没有map了,使用npm install vue-router@0.7.13 命令兼容1.0版本vue 但是安装完之后会出现一个错误: Cannot read prope ...

  8. BZOJ 4555: [Tjoi2016&Heoi2016]求和 [FFT 组合计数 容斥原理]

    4555: [Tjoi2016&Heoi2016]求和 题意:求\[ \sum_{i=0}^n \sum_{j=0}^i S(i,j)\cdot 2^j\cdot j! \\ S是第二类斯特林 ...

  9. UVa 1378 A Funny Stone Game [博弈论 SG函数]

    A Funny Stone Game 题意: $n \le 23$堆石子,每次选择$i < j \le k$,从$i$拿走1颗$j,k$各放入一颗,不能取就失败.求先手是否必胜以及第一次取的策略 ...

  10. nginx隐藏版本号

    在实际运用nginx中我们最好将我们的版本号直接隐藏,因为有些版本号的nginx被爆出了漏洞,所以我们为了安全起见,最好将我们的版本号隐藏. 1.对于未安装的nginx我们使用源码编译安装才可以将版本 ...