组队赛三 dfs搜索
来源:互联网 发布:cms视频监控软件下载 编辑:程序博客网 时间:2024/06/04 17:54
先要牢记string的截取部分的函数。。。
#include <iostream>
#include <string>
using namespace std ;
void main()
{
string s="ABAB";
cout << s.substr(2) <<endl ; //输出AB
cout << s.substr(0,2) <<endl ; //同上
cout << s.substr(1,2) <<endl ; //输出BA
}
我们令咒文只由两种字符 'E' 和 'X' 组成,对于一个咒文 S 我们有两种变换:
- 在 S 的末尾追加字符 'E'。
- 在 S 的末尾追加字符 'X',然后翻转整个咒文(翻转之后,刚才加的 'X' 实际上去到了咒文的开头)。
我们给出一个较短的咒文 S 和一个较长的咒文 T (我们保证 T 的长度严格大于 S 的长度),问能否通过上述变换把 S 转化为T 。
分析:自己没有想到是从target串去搜initial串。。。。结果别人都会,我不会,,自己从S搜T,显然会超时。。
#include<cstdio>#include<cstring>#include<algorithm>#include<queue>#include<string>#include<cstring>#include<iomanip>#include<iostream>#include<stack>#include<cmath>#include<map>#include<vector>#define ll long long#define inf 0x3f3f3f3f#define INF 1000000000#define bug1 cout<<"bug1"<<endl;#define bug2 cout<<"bug2"<<endl;#define bug3 cout<<"bug3"<<endl;using namespace std;string a,b;int lena;map<string,int>mp;bool dfs(string tmp){ int lenb=tmp.length(); //cout<<tmp<<endl; if(lena==lenb)return a==tmp; //多理解下这里为什么是这样剪枝吧。 if(tmp[lenb-1]=='E'){ string temp=tmp.substr(0,lenb-1);// //在这个地方自己又错了。。 //以为substr(first,second)是截取前面到后面的字符串,其实是从first开始,长度为second的字符串 if(dfs(temp))return true; } if(tmp[0]=='X'){ string temp1=tmp.substr(1,lenb-1); reverse(temp1.begin(),temp1.end()); if(dfs(temp1))return true; } return false;}int main(){ int t; scanf("%d",&t); while(t--){ cin>>a>>b; cout<<a.substr(0,a.length()-1)<<endl; cout<<b.substr(0,b.length()-1)<<endl; mp.clear(); lena=a.length(); if(dfs(b))cout<<"Explosion!\n"; else cout<<"Dekimasen\n"; }}
0 0
- 组队赛三 dfs搜索
- 组队赛#1 解题总结 ZOJ 3803 YY's Minions (DFS搜索+模拟)
- nyist---组队赛(三)
- 【组队赛三】-C cf448B
- 【组队赛三】-D 优先队列 cf446B
- 【组队赛三】-E Binary Search cf448D
- ACM组队安排 (DFS+计数原理)
- 搜索 dfs
- dfs搜索
- DFS搜索
- 搜索dfs
- 图论(三)--深度优先搜索(DFS)
- 7 28 组队赛
- 组队赛130827
- 组队赛130926
- 国庆组队赛131002
- 组队_浙江省赛
- CUGBACM_组队赛1
- Red Hat Enterprise Linux Server(RHEL) yum安装软件时This system is not registered with RHN. RHN support wi
- 建立一个邮箱,OSMboxCreate()
- NYOJ 55 懒省事的小明
- maven(16)-灵活的环境构建
- 最短路径问题
- 组队赛三 dfs搜索
- 最短路径问题
- 数据结构(c语言版)学习笔记——排序算法
- 动态库与静态库的区别
- 递归递推训练A-母牛的故事
- 最短路径问题
- j2EE 介绍
- 欢迎使用CSDN-markdown编辑器
- [系列]OS学习-自己写操作系统(1)