Submission #163723
Source Code Expand
#include <iostream> #include <string> #include <queue> using namespace std; int main(){ int r,c,sy,sx,gy,gx,i,j,nowx,nowy,newx,newy; string s[100]; bool b[100][100]; int cnt[100][100]; int dx[4]={0,-1,0,1},dy[4]={1,0,-1,0}; cin >> r >> c; cin >> sy >> sx; cin >> gy >> gx; for(int i=0;i<r;i++) cin >> s[i]; sy--;sx--;gy--;gx--; for(i=0;i<r;i++){ for(j=0;j<c;j++){ b[i][j] = false; cnt[i][j] = 0; } } queue<int> quex, quey; quex.push(sx); quey.push(sy); while(quex.size() > 0){ nowx = quex.front(); nowy = quey.front(); // printf("cnt[%d][%d]=%d\n",nowy,nowx,cnt[nowy][nowx]); quex.pop(); quey.pop(); if(nowx == gx && nowy == gy){break;} for(i = 0; i < 4; i++){ newx = nowx + dx[i]; newy = nowy + dy[i]; if(s[newy][newx]=='#' || b[newy][newx]){continue;} quex.push(newx); quey.push(newy); b[newy][newx] = true; cnt[newy][newx] = cnt[nowy][nowx] + 1; } } printf("%d\n", cnt[gy][gx]); return 0; }
Submission Info
Submission Time | |
---|---|
Task | C - 幅優先探索 |
User | fuzuiR |
Language | C++ (G++ 4.6.4) |
Score | 0 |
Code Size | 1031 Byte |
Status | CE |
Compile Error
./Main.cpp: In function ‘int main()’: ./Main.cpp:51:29: error: ‘printf’ was not declared in this scope