백준 알고리즘/BFS47 백준 1697번 C++ 2019. 8. 7. 백준 2178번 C++ 2019. 8. 7. 백준 7576번 C++ #include #include using namespace std; const int MAX = 1001;int n, m;int tomato[MAX][MAX];int notomato = 0;queue finish; typedef struct {int a, b;}Move;Move mv[4] = { {1,0},{-1,0},{0,-1},{0,1} }; bool allfinish() {int finishtomato = 0; for (int i = 0; i < n; i++) {for (int j = 0; j < m; j++) {if(tomato[i][j] == 1)finishtomato++;}}return ((m*n - notomato) == finishtomato);} int bfs() {int day = 0.. 2019. 2. 24. 백준 1697번 C++ #include #include #include #include using namespace std; const int MAX = 100001;int n, k;queue q;int visited[MAX]; int bfs(int i) {int answer = 0;if (i == k)return answer;q.push(make_pair(i, 0));visited[i] = 1; while (!q.empty()) {int currentlocation = q.front().first;int currenttime = q.front().second;q.pop();if (currentlocation == k) {answer = currenttime;break;} if ((currentlocation - 1) >= 0.. 2019. 2. 22. 이전 1 ··· 6 7 8 9 10 11 12 다음