127. Word Ladder int size = q.size(); for(int k = 0; k < size; k++){//for 次数 找到一个erase一个 q里面加入的是所有可能的替换一个字母过后的word 所以要在k的loop里记录替换次数 130. Surrounded Regions 刚拿到这个题,首先得想法就是BFS.对于每一个O,扫描其相邻节点,然后标示之,如果一个联通区域中有任何一个O在边界上,则保留之,否则清除该联通域. 小数据可以过,但是大数据提示Memor
一.求所有顶点到s顶点的最小步数 //BFS宽度优先搜索 #include<iostream> using namespace std; #include<queue> #define MAX 10000 ][],int s,int n)//从(si,sj)出发能到的位置以及距离 { int *flag=new int[n];//顶点是否被遍历过,0未遍历,1已入队,2已出队 int *dist=new int[n]; int i; ;i<n;i++) { flag[i]
Fat brother and Maze are playing a kind of special (hentai) game on an N*M board (N rows, M columns). At the beginning, each grid of this board is consisting of grass or just empty and then they start to fire all the grass. Firstly they choose two gr
宽度优先搜索(BFS) #include<cstdio> #include<cstring> #include<iostream> #include<algorithm> #include<queue> #define x first #define y second using namespace std; typedef pair<int,int> PII; const int N=210; char g[N][N]; int d