Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
ffsfsfsfsfsferwfehtyjrvgjb
#include<iostream> #include<vector> #include<queue> using namespace std; int main() { int n, x1, y1, x2, y2; cin >>n>> x1 >> y1 >> x2 >> y2; pair<int,int>start= make_pair(x1-1, y1-1),end = make_pair(x2-1,y2-1); vector<vector<vector<pair<int,int>>>>g(n,vector<vector<pair<int,int>>>(n)); vector<vector<bool>>used(n,vector<bool>(n)); vector<vector<int>>d(n,vector<int>(n)); queue<pair<vector<pair<int,int>>,pair<int,int>>>q; for (int x = 0; x < n; ++x) { for (int y = 0; y < n; ++y) { //лево if (x - 2 >= 0 && y - 1 >= 0) g[x][y].push_back(make_pair(x - 2, y - 1)); if (x - 2 >= 0 && y + 1 < n) g[x][y].push_back(make_pair(x - 2, y + 1)); //право if (x + 2 < n && y - 1 >= 0) g[x][y].push_back(make_pair(x + 2, y - 1)); if (x + 2 < n && y + 1 < n) g[x][y].push_back(make_pair(x + 2, y + 1)); //верх if (x - 1 >= 0 && y - 2 >= 0) g[x][y].push_back(make_pair(x - 1, y - 2)); if (x + 1 < n && y - 2 >= 0) g[x][y].push_back(make_pair(x + 1, y - 2)); //низ if (x - 1 >= 0 && y + 2 < n) g[x][y].push_back(make_pair(x - 1, y + 2)); if (x + 1 < n && y + 2 < n) g[x][y].push_back(make_pair(x + 1, y + 2)); } } q.push(make_pair(g[start.first][start.second], make_pair(start.first, start.second))); while (!q.empty()) { pair<vector<pair<int, int>>, pair<int, int>>v = q.front(); q.pop(); for (int i = 0; i < v.first.size(); ++i) { if (!used[v.first[i].first][v.first[i].second]) { used[v.first[i].first][v.first[i].second] = true; d[v.first[i].first][v.first[i].second] = d[v.second.first][v.second.second]+1; q.push(make_pair(g[v.first[i].first][v.first[i].second],make_pair(v.first[i].first, v.first[i].second))); } } } cout << d[end.first][end.second]; }
run
|
edit
|
history
|
help
0
ReplaceNotExpectedCharacters
Armstrong
Kumaran-RegText-CityStatePostalCode Parsing
XPath
Customised Code Dashboard
UFC 271 LIVE STREAM FREE REDDIT online
24 101 251 Primes
function in event
ConcurrentStack<T>
Trent Butler All Dead Example