評測記錄:
給若干個變化規則,表示a中的a
xa_x
ax子串可以變化為b
xb_x
bx中的子串,求至少要多少次變化才可以變為b子串。
暴力廣蒐用map
mapma
p庫判重。
#include
#include
#include
#include
#include
using
namespace std;
queue q;
mapint> d;
string s,ans,a[7]
,b[7];
int n;
bool
cmps
(string s,string a,
int first,
int len)
intbfs()
for(
int j=
1;j<=n;j++
)for
(int i=
0;isize()
;i++)if
(cmps
(x,a[j]
,i,a[j]
.size()
))x=q.
front()
;}q.
pop();
}return-1
;}intmain()
while
(cin>>a[n]
>>b[n]
) n++
; n--
;int answer=
bfs();
if(answer==-1
)printf
("no answer!");
else
printf
("%d"
,answer)
;}
P1032 字串變換 bfs
由數字00組成的方陣中,有一任意形狀閉合圈,閉合圈由數字11構成,圍圈時只走上下左右44個方向。現要求把閉合圈內的所有空間都填寫成22.例如 6 times 66 6的方陣 n 6n 6 塗色前和塗色後的方陣如下 0 0 0 0 0 0 0 0 1 1 1 1 0 1 1 0 0 1 1 1 0 0...
P1032 字串變換
思路 採用bfs 我們遍歷字串a的每個字元,判斷當前字串i位置之後可不可以替換,如果可以替換,我們就把替換後的字串 a 放入佇列。如果出現的我們想要的字串,根據bfs的性質,那麼就直接記錄此時的步數。1 include 2 include 3 include 4 include 5 include ...
P1032 字串變換
迭代加深難題 右手進入傳送門 大意是這樣的 給定兩個字串a,b以及至多六個變換規則 規則指a1 b1,a2 b2,在a中的子串 a1可以變換為b1,a2可以變換為 b2 求最少變換步數,若在10步 包含10步 以內能將a變換為b,則輸出最少的變換步數 否則輸出 no answer 看到題目要求的10...