BFS

알고리즘 문제 풀이/1DP_과제(~180615)

180205_2589_보물섬

//https://www.acmicpc.net/problem/2589 #include #include #include using namespace std;char map[50][50];int visited[50][50];int N,M, mx; int dy[4]={0,0,1,-1};int dx[4]={1,-1,0,0}; void init(){ for(int i=0; imx) mx=visited[ny][nx]; } } } }} int main(){ cin >> N >> M; for(int i=0; i> map[i]; for(int i=0; i

알고리즘 문제 풀이/1DP_과제(~180615)

180202_2146_다리 만들기

//https://www.acmicpc.net/problem/2146 #include #include using namespace std;bool map[100][100];int visited[100][100];int visited2[100][100];int N, cnt;int min1=10001; int dy[4]={0,0,1,-1};int dx[4]={1,-1,0,0}; void dfs(int y, int x, int land){ visited[y][x]=land; for(int i=0; i=0 && ny=0 && nx

알고리즘 문제 풀이/1DP_과제(~180615)

180131_7562_나이트의 이동

//https://www.acmicpc.net/problem/7562#include #include using namespace std;int map[300][300];int sy,sx,dy,dx, I; int diry[8]={2,2,1,1,-1,-1,-2,-2};int dirx[8]={-1,1,-2,2,-2,2,-1,1}; void bfs(int starty, int startx){ queue q; q.push(starty*1000+startx); map[starty][startx]=1; bool chk=1; while(chk && !q.empty()){ int nowy=q.front()/1000; int nowx=q.front()%1000; q.pop(); for(int i=0; i=0 && next..

알고리즘 문제 풀이/1DP_과제(~180615)

180131_2644_촌수계산

//https://www.acmicpc.net/problem/2644 #include #include #include using namespace std;int parent[101]; // parent[i] :: i의 부모int chon[101];int n; void bfs(int start){ queue q; q.push(start); chon[start]=0; while(!q.empty()) { int now=q.front(); q.pop(); for(int i=1; i> n >> a >> b >> m; for(int i=0; i> x >> y; parent[y]=x;//y의 부모가 x } memset(chon, -1, sizeof(chon)); bfs(a); cout

bong sue
'BFS' 태그의 글 목록 (3 Page)