Archives
Trending
Support
Login
clear text
XML
Django
JavaScript
MATLAB
C
C++
C#
Python
SQL
Shell
Bash
Markdown
YAML
JSON
HTML
CSS
PHP
Java
Ruby
Go
Rust
Swift
Kotlin
Arduino
TypeScript
Perl
Autohotkey
Lua
SQF
R
Scala
Haskell
Groovy
Dart
Clojure
VB.NET
Objective-C
PowerShell
Bash
CoffeeScript
Verilog
#include
#include
#include
using namespace std; int main() { int n, m; cin >> n >> m; char mat[n][m]; int si, sj; for(int i = 0; i < n; i++) { for(int j = 0; j < m; j++) { cin >> mat[i][j]; if(mat[i][j] == 'S') { si = i; sj = j; } } } bool visited[n][m]; for(int i = 0; i < n; i++) { for(int j = 0; j < m; j++) { visited[i][j] = false; } } queue
q; q.push(si); q.push(sj); q.push(0); visited[si][sj] = true; while(!q.empty()) { int ci = q.front(); q.pop(); int cj = q.front(); q.pop(); int distanca = q.front(); q.pop(); if(mat[ci][cj] == 'E') { cout << distanca << endl; break; } if(ci + 1 < n and mat[ci + 1][cj] != '#' and !visited[ci + 1][cj]) { visited[ci + 1][cj] = true; q.push(ci + 1); q.push(cj); q.push(distanca + 1); } if(ci - 1 >= 0 and mat[ci - 1][cj] != '#' and !visited[ci - 1][cj]) { visited[ci - 1][cj] = true; q.push(ci - 1); q.push(cj); q.push(distanca + 1); } if(cj + 1 < m and mat[ci][cj + 1] != '#' and !visited[ci][cj + 1]) { visited[ci][cj + 1] = true; q.push(ci); q.push(cj + 1); q.push(distanca + 1); } if(cj - 1 >= 0 and mat[ci][cj - 1] != '#' and !visited[ci][cj - 1]) { visited[ci][cj - 1] = true; q.push(ci); q.push(cj - 1); q.push(distanca + 1); } } return 0; }
Mark as private (unlisted)
for 30 minutes
for 6 hours
for 1 day
for 1 week
for 1 month
for 1 year
everlasting (like CCCP)