ZOJ 1091 依然是广搜哒~~
2017-07-30 11:11
316 查看
从昨天中午开始写,到晚上柑橘差不多了提交的时候一直都是SF T_T~不过今天再看了一眼发现是visi数组写成8×8了,,所以错了!!!今天要努力啦!!!
#include <cstring> #include <iostream> #include <queue> using namespace std; typedef struct node { int X; int Y; int step; } pos; queue<pos> Q; int vist[9][9]; int jump[9][2] = {{0, 0}, {-1, -2}, {-2, -1}, {-2, 1}, {-1, 2}, {1, -2}, {2, -1}, {2, 1}, {1, 2}}; int main(void) { char x1, x2; int y1, y2, a, b; pos r; pos arr_f_Q[100000]; while (cin >> x1 >> y1 >> x2 >> y2) { int count = -1; memset(vist, 0, sizeof(vist)); while (!Q.empty()) Q.pop(); a = x1 - 'a' + 1; b = x2 - 'a' + 1; r.X = a; r.Y = y1; r.step = 0; Q.push(r); while (!Q.empty()) { count++; arr_f_Q[count] = Q.front(); Q.pop(); if (arr_f_Q[count].X == b && arr_f_Q[count].Y == y2) { break; } for (int i = 1; i <= 8; i++) { r.X = arr_f_Q[count].X + jump[i][0]; r.Y = arr_f_Q[count].Y + jump[i][1]; if (r.X >= 1 && r.X <= 8 && r.Y >= 1 && r.Y <= 8 && !vist[r.X][r.Y]) { vist[r.X][r.Y] = 1; r.step = arr_f_Q[count].step + 1; Q.push(r); } } } cout << "To get from " << x1 << y1 << " to " << x2 << y2 << " takes " << arr_f_Q[count].step << " knight moves." << endl; } return 0; }
相关文章推荐
- ZOJ_1091-Knight Moves
- ZOJ Problem Set - 1091
- ZOJ-1091-Knight Moves
- zoj - 1091 - Knight Moves(广度优先法)
- zoj1091-Knight Moves
- zoj 1091(pku2243,hdu1372) Knight Moves(广搜)
- UVa 439/HDU 1372/POJ 2243/ZOJ 1091 Knight Moves(BFS&纯数学方法)
- ZOJ 1091 Knight Moves (BFS)
- ZOJ——1091(宽搜)
- zoj 1091 BFS简单搜索
- ZOJ-1091-Knight Moves
- ZOJ-1091-Knight Moves
- ZOJ--1091:Knight Moves(dfs)
- 单源最短路径 ZOJ 1091 Knight Moves
- ZOJ-1091 Knight Moves(bfs)
- ZOJ 1091
- zoj1091 Knight Moves
- zoj - 1091 - Knight Moves(广度优先地图记数法)
- BFS例题 ZOJ——1091 Knight Moves
- ZOJ 1091 Knight Moves(各大算法集锦)