1099 字串变换

2002年NOIP全国联赛提高组

 时间限制: 1 s
 空间限制: 128000 KB
 题目等级 : 黄金 Gold
 
 
 
题目描述 Description

已知有两个字串 A$, B$ 及一组字串变换的规则(至多6个规则):
     A1$ -> B1$
     A2$ -> B2$
  规则的含义为:在 A$中的子串 A1$ 可以变换为 B1$、A2$ 可以变换为 B2$ …。
    例如:A$='abcd' B$='xyz'
  变换规则为:
    ‘abc’->‘xu’ ‘ud’->‘y’ ‘y’->‘yz’

  则此时,A$ 可以经过一系列的变换变为 B$,其变换的过程为:
   ‘abcd’->‘xud’->‘xy’->‘xyz’

  共进行了三次变换,使得 A$ 变换为B$。

输入描述 Input Description

输入格式如下:

   A$ B$
   A1$ B1$ \
   A2$ B2$  |-> 变换规则
   ... ... / 
  所有字符串长度的上限为 20。

输出描述 Output Description

若在 10 步(包含 10步)以内能将 A$ 变换为 B$ ,则输出最少的变换步数;否则输出"NO ANSWER!"

样例输入 Sample Input

abcd xyz
abc xu
ud y
y yz

样例输出 Sample Output

3

数据范围及提示 Data Size & Hint

hehe

string判重+删除

map记录步数,,

但是不知道为啥最后一个点过不了?

 #include<iostream>
#include<cstdio>
#include<queue>
#include<cstring>
#include<cstdlib>
#include<map>
using namespace std;
string a,b;
struct node
{
string x;
string y;
}bc[];
int num=;
int step=;
map<string,int>bushu;
string pc;//
int vis[];
void bfs()
{
queue<string>q;
q.push(a);
bushu[q.front()]=; while(q.size()!=)
{
int numm=q.size();
string p=q.front();
if(p==b)
{
printf("%d",bushu[p]);
exit();
}
pc=pc+" "+p+" ";
q.pop();
for(int i=;i<=num;i++)
{
string dd=p;
string change=p;
while()
{
int where=change.find(bc[i].x);
if(where!=-&&vis[where]==)
{
vis[where]=;
change[where]='*'; int l=bc[i].x.length();
p.replace(where,l,bc[i].y); if(p==b)
{
printf("%d",bushu[dd]+);
exit();
} if(pc.find(p)!=-)continue;// 判重
pc=pc+" "+p+" "; bushu[p]=bushu[dd]+; cout<<step<<" "<<bushu[p]<<" "<<p<<endl; if(p==b)
{
printf("%d",bushu[p]);
exit();
}
else
{step++;q.push(p);}
if(bushu[p]>)
{printf("NO ANSWER!");exit();}
p=dd;
}
else break;
} }
}
}
int main()
{
cin>>a>>b;
while(cin>>bc[num].x>>bc[num].y){num++;}
bfs();
printf("NO ANSWER!");
return ;
}

最新文章

  1. error C2512: “Rectangle”: 没有合适的默认构造函数可用
  2. javascript全局变量和局部变量
  3. 关于/etc/rc.local以及/etc/init.d
  4. SQL SERVER安装序列号
  5. WWDC2016-session401-CodeSign大改版
  6. 【BZOJ】【1046】/【POJ】【3613】【USACO 2007 Nov】Cow Relays 奶牛接力跑
  7. Cortex-M3动态加载三(模块调用系统函数)
  8. Hex Workshop(16进制编辑利器) 6.7.2绿色版
  9. python自动化测试应用-番外篇--接口测试2
  10. bzoj2002: [Hnoi2010]Bounce 弹飞绵羊 [分块][LCT]
  11. Oracle AP Invoice APIs
  12. 36ArcGIS API for JavaScript3.X 系列加载天地图(经纬度)
  13. leetcode — single-number
  14. JAVA日常之三
  15. 使用spark操作kudu
  16. 二进制 转换成十进制 BCD码(加3移位法)
  17. job.yml
  18. URL中文编码
  19. 如果要写php扩展啥的, 要看什么?
  20. windows系统bat方式启动tomcat出现java.lang.OutOfmemoryError:PermGen Space 错误

热门文章

  1. [HAOI 2012] 外星人
  2. 17.for循环语句
  3. Flutter实战视频-移动电商-14.首页_url_launcher一键拨打店长电话
  4. shell初级-----更多结构化命令
  5. vue中excel导入导出组件
  6. POJ 3067【树状数组】
  7. laravel SQL语句
  8. ssh 下载文件以及上传文件到服务器
  9. Linq 知识总结
  10. Unrecogized font family ‘Ionicons’ 在ios上报错,android正常