POJ 3087
来源:互联网 发布:庞博 程序员 编辑:程序博客网 时间:2024/06/08 14:55
题目大意:输入s1,s2按图方式合成s12如果s12与输入的目标一致,则完成,否则将下部分给s1,上部分给s2,直到完成,或,确认不能完成目标。输出最少次数,不完成则-1。
解题思路:不太懂为什么要用bfs,直接模拟就好了。。。或者暴力到10000他也会ac
ac代码:
#include <iostream>#include <string>using namespace std;int n, m, temp, count=1;string a, b, c;string change(string &a, string &b){string temp3="";int len=a.size();for (int i=0; i<2*len; i++){if (i%2)temp3 += a[i/2];elsetemp3 += b[i/2];}a = b = "";for (int i=0; i<2*len; i++){if (i<len)a += temp3[i];elseb += temp3[i];}return temp3;}int bfs(){string tt=a, kk=b, temp2;temp2 = change(tt, kk);int cnt = 1;while (!(tt == a && kk == b)){if (temp2 == c)return cnt;temp2 = change(tt, kk);cnt++;}return 0;}int main(){scanf("%d", &n);while (n--){scanf("%d", &m);cin >> a >> b >> c;temp = bfs();if (temp)printf("%d %d\n", count++, temp);elseprintf("%d -1\n", count++);}return 0;}
阅读全文
0 0
- POJ 3087
- poj 3087
- POJ 3087
- poj-3087
- poj 3087
- poj 3087
- 3087POJ
- poj--3087
- POJ 3087
- poj 3087
- POJ 3087
- POJ 3087
- POJ 3087
- poj 3087解题报告
- Poj 3087 (bfs)
- poj 3087 模拟
- poj 3087 模拟
- poj 3087 模拟题
- spring属性注入必须有默认构造方法
- iOS 3D Touch超详细入门(附带demo示例代码)
- csu1115 最短的名字 字典树模板
- 2017.9.2总结3-分割田地
- css基础(4)
- POJ 3087
- Android 中怎样查找SELinux导致的权限受限有关问题
- 小事: 自动生成Getter代码
- UVA 11624
- docker 使用Dockerfile 创建带jdk 和tomcat的镜像
- 2439四叶草魔杖
- UILabel简单高效实现圆角的方式
- ES Java API
- 替换空格