BFS 瑪雅人的密碼

2021-09-22 22:39:48 字數 492 閱讀 1082

時間限制:1秒 空間限制:65536k 熱度指數:5412

瑪雅人有一種密碼,如果字串**現連續的2012四個數字就能解開密碼。給乙個長度為n的字串,(2=示例1

1. 典型的bfs題目,節點為字串

2. 巧妙地運用map來判斷搜尋樹中是否有重複的節點

3. s.find("2012")!=string::npos 匹配字串中的模式

#includeusing namespace std;

bool judge(string s)

string myswap(string s, int i)

int main()

q.push(s);

m[s] = 0;

while(!q.empty())

else}}

if(flag) break;

}if(!flag)

}return 0;

}

瑪雅人的密碼bfs

如何用佇列廣度優先遍歷所有可能性 queue 如何判別並標示某串是否訪問過 map 如何記錄某串已經交換字元的次數 子串2012是否存在 include include include include include include using namespace std int count 3 t...

瑪雅人的密碼 BFS

瑪雅人有一種密碼,如果字串 現連續的2012四個數字就能解開密碼。給乙個長度為n的字串,2 輸入包含多組測試資料,每組測試資料由兩行組成。第一行為乙個整數n,代表字串的長度 2 n 13 第二行為乙個僅由0 1 2組成的,長度為n的字串。對於每組測試資料,若可以解出密碼,輸出最少的移位次數 否則輸出...

瑪雅人的密碼(利用bfs)

瑪雅人有一種密碼,如果字串中出現連續的2012四個數字就能解開密碼。給乙個長度為n的字串,2 示例1 複製5 02120 複製1 解析 利用bfs的思想進行 如下 方法一 bfs 純c,無利用queue函式 include include include includechar pass 2012 ...