본문 바로가기

분류 전체보기439

백준 2667번 C++ #include #include #include #include #include using namespace std; const int MAX = 26;int n;string arr[MAX];vector answer;typedef struct {int a, b;}Move;Move mv[4] = { {1,0},{-1,0},{0,1},{0,-1} }; bool checkfinish() {for (int i = 0; i < n; i++) {for (int j = 0; j < n; j++) {if (arr[i][j] == '1')return false;}}return true;} int bfs(int a,int b) {int answer = 1;queue q;q.push(make_pair(a, b));arr[a.. 2019. 2. 25.
백준 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.
백준 2178번 C++ #include #include #include using namespace std; const int MAX=101;int n, m;int arr[MAX][MAX];queue way;int visited[MAX][MAX]; typedef struct {int x, y;}Move;Move mv[4] = { {0,-1},{0,1},{1,0},{-1,0} }; int bfs() {int answer = 0;way.push(make_pair(1,make_pair(1,1)));visited[1][1] = 1; while (!way.empty()) {int x = way.front().first;int y = way.front().second.first;int count = way.front().second.se.. 2019. 2. 19.