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
using namespace std; #define pb push_back #define ff first #define ss second #define int long long const int n = 5; bool mapp[n][n] = {}; bool vis[n][n] = {false}; int dx[4] = {-1, 0, 1, 0}; int dy[4] = {0, 1, 0, -1}; string steps = "URDL"; int previous_step[n][n]; // 0 = up, 1 = right, 2 = down, 3 = left vector
bfs_returner(int startx, int starty, int endx, int endy){ int V = n*n; vector
res; queue
> q; for(int i=0; i
u = q.front(); q.pop(); for (int i = 0; i < 4; i++) { pair
v = {u.first + dx[i], u.second + dy[i]}; if (v.first < 0 || v.first >= n || v.second < 0 || v.second >= n) continue; if (mapp[v.first][v.second] == 1) continue; if (vis[v.first][v.second] == 1) continue; vis[v.first][v.second] = true; previous_step[v.first][v.second] = i; q.push(v); } } if (vis[endx][endy]==1) { while(startx!=endx or starty!=endy) { int p = previous_step[endx][endy]; res.push_back(p); endx = endx - dx[p]; endy = endy - dy[p]; } } reverse(res.begin(), res.end()); return res; } void test(){ //ifstream cin("perimeter.in"); //ofstream cout("perimeter.out"); for(int i=0; i<5; i++){ for(int j=0; j<5; j++){ cin >> mapp[i][j]; } } int startxx, startyy, endxx, endyy; cin >> startxx >> startyy; cin >> endxx >> endyy; vector
ans = bfs_returner(startxx, startyy, endxx, endyy); for(int i=0; i
> t; //while(t--) test(); }
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)