Submission #162587
Source Code Expand
#include <iostream> #include <sstream> #include <string> #include <vector> #include <set> using namespace std; //void print() //{ // int R = g_board.size(); // int C = g_board[0].size(); // for(int y=0; y<R; ++y) // { // for(int x=0; x<C; ++x) // { // cout << g_board[y][x]; // } // // cout << endl; // } // cout << "-----------------------" << endl; //} int main(int argc, char* argv[]) { vector<vector<string>> g_board; int R, C; cin >> R >> C; int sy, sx; cin >> sy >> sx; int gy, gx; cin >> gy >> gx; vector<string> board; for(int y=0; y<R; ++y) { string line; cin >> line; board.push_back(line); } set<int> prevPoints; set<int> curPoints; curPoints.insert((sy - 1) * C + (sx - 1)); int currentDepth = 0; int tmp = 0; while(true) { bool isFound = false; stringstream ss; string sCurrentDepth; ss << currentDepth; sCurrentDepth = ss.str(); set<int>::iterator it; prevPoints.clear(); for(it = curPoints.begin(); it!=curPoints.end(); ++it) { prevPoints.insert(*it); } curPoints.clear(); for(it = prevPoints.begin(); it!=prevPoints.end(); ++it) { int coord = *it; int y = (int)coord / C; int x = coord % C; g_board[y][x] = sCurrentDepth; if(x == gx - 1 && y == gy - 1) { isFound = true; break; } if(g_board[y - 1][x] == ".") { curPoints.insert((y - 1) * C + x); } if(g_board[y + 1][x] == ".") { curPoints.insert((y + 1) * C + x); } if(g_board[y][x - 1] == ".") { curPoints.insert(y * C + x - 1); } if(g_board[y][x + 1] == ".") { curPoints.insert(y * C + x + 1); } } if(isFound) { break; } currentDepth++; tmp++; } //print(); cout << currentDepth << endl; return 0; }
Submission Info
Submission Time | |
---|---|
Task | C - 幅優先探索 |
User | wfalps |
Language | C++ (G++ 4.6.4) |
Score | 0 |
Code Size | 1863 Byte |
Status | CE |
Compile Error
./Main.cpp: In function ‘int main(int, char**)’: ./Main.cpp:26:25: error: ‘g_board’ was not declared in this scope ./Main.cpp:26:22: error: ‘>>’ should be ‘> >’ within a nested template argument list