#include #include #include #include #include #include #include #include using namespace std; struct Cell { Cell(void) : blocked{false}, mine{false},tunnel{false}, visited{false}, tr{0}, tc{0} {} bool blocked; bool mine; bool tunnel; bool visited; size_t tr, tc; // tunnel exit }; int main() { /* Enter your code here. Read input from STDIN. Print output to STDOUT */ std::ios::sync_with_stdio(false); std::cin.tie(nullptr); size_t R, C, T; std::cin >> R >> C >> T; std::vector> maze(R, std::vector(C, Cell{})); size_t fsr, fsc; size_t er, ec; for(size_t r{0}; r> s; for(size_t c{0}; c> r1 >> c1 >> r2 >> c2; --r1; --c1; --r2; --c2; maze[r1][c1].tunnel=true; maze[r1][c1].tr=r2; maze[r1][c1].tc=c2; maze[r2][c2].tunnel=true; maze[r2][c2].tr=r1; maze[r2][c2].tc=c1; } std::default_random_engine generator; std::uniform_int_distribution roll2{0, 1}; std::uniform_int_distribution roll3{0, 2}; std::uniform_int_distribution roll4{0, 3}; size_t wins{0}, losses; struct State { State(size_t row, size_t col, bool t) : r{row}, c{col}, tunnel{t} {} size_t r,c; bool tunnel; }; std::stack dfs; dfs.push(State{fsr, fsc, false}); while(!dfs.empty()) { State state{dfs.top()}; dfs.pop(); size_t fr=state.r; size_t fc=state.c; bool tunnel=state.tunnel; maze[fr][fc].visited=true; //std::cout << fr << ' ' << fc << std::endl; if (fr==er && fc==ec) { ++wins; } else if (maze[fr][fc].mine) { ++losses; } else if (maze[fr][fc].tunnel && !tunnel) { dfs.push(State{maze[fr][fc].tr, maze[fr][fc].tc, true}); } else { // get number of free directions std::vector> freeCells; if (fr>0 && !maze[fr-1][fc].blocked) { freeCells.emplace_back(fr-1, fc); } if (fr0 && !maze[fr][fc-1].blocked) { freeCells.emplace_back(fr, fc-1); } if (fc& freeCell : freeCells) { if (!maze[freeCell.first][freeCell.second].visited) dfs.push(State{freeCell.first, freeCell.second, false}); } } } } std::cout << static_cast(wins)/(wins+losses) << std::endl; /* for(size_t trial{0}; trial> freeCells; if (fr>0 && !maze[fr-1][fc].blocked) { freeCells.emplace_back(fr-1, fc); } if (fr0 && !maze[fr][fc-1].blocked) { freeCells.emplace_back(fr, fc-1); } if (fc(Trials) << std::endl; */ return 0; }