Codefoeces 3A. Shortest path of the king
来源:互联网 发布:asp 导出数据到excel 编辑:程序博客网 时间:2024/06/07 13:08
代码:
/*棋盘长度 codeforces 3-A*/#include <stdio.h>#include <algorithm>#include <string>#include <queue>#include <iostream>using namespace std;const int MAXN = 10;struct Grid{ int row; int col; Grid(){}; Grid(int x, int y) : row(x), col(y){} bool operator!=(const Grid &g) const { if(row != g.row || col != g.col) return true; return false; }};string Hash[10] = {"LD", "D", "RD", "L", "NONE", "R", "LU", "U", "RU"};int chessBoard[MAXN][MAXN];int dis[MAXN][MAXN];Grid father[MAXN][MAXN];string mov[MAXN][MAXN];bool visit[MAXN][MAXN];void Init(){ for(int i = 0; i < 10; ++i) { visit[i][0] = visit[i][9] = visit[9][i] = visit[0][i] = true; }}void BFS(Grid start){ queue<Grid> que; que.push(start); dis[start.row][start.col] = 0; visit[start.row][start.col] = true; while(!que.empty()) { Grid temp = que.front(); int count = 0; for(int i = -1; i <= 1; ++i) for(int j = -1; j <= 1; ++j) { int x = temp.row + i, y = temp.col + j; if(!visit[x][y]) { visit[x][y] = true; mov[x][y] = Hash[count]; dis[x][y] = dis[temp.row][temp.col] + 1; father[x][y] = temp; que.push(Grid(x, y)); } ++count; } que.pop(); }}void PrintPath(Grid end, Grid start){ if(end != start) { PrintPath(father[end.row][end.col], start); cout << mov[end.row][end.col] << endl; }}int main(){#ifdef _LOCAL freopen("F://input.txt", "r", stdin);#endif char a, b; int x, y; scanf("%c%d", &a, &x); getchar(); scanf("%c%d", &b, &y); Grid start(x, a - 'a' + 1), end(y, b - 'a' + 1); Init(); BFS(start); printf("%d\n", dis[end.row][end.col]); PrintPath(end, start); return 0;}
0 0
- Codefoeces 3A. Shortest path of the king
- 3A - Shortest path of the king
- A - Shortest path of the king
- A. Shortest path of the king
- A. Shortest path of the king
- CF 3A Shortest path of the king
- coderforce 3A-Shortest path of the king
- codeforces 3A - Shortest path of the king
- Codeforces 3A Shortest path of the king BFS
- code forces 3A Shortest path of the king
- codeforces 3A Shortest path of the king
- 【pair_简单贪心】#3 A. Shortest path of the king
- Codeforces 3A Shortest Path of the King
- Codeforces Round #3A. Shortest path of the king
- Codeforces Beta Round #3 A. Shortest path of the king
- Codeforces 3A. Shortest path of the king(贪心:暴力)
- CodeForces 3A - Shortest path of the king
- 【codeforces#3A】Shortest path of the king
- Kinect API 简述
- GNU Linux 64位系统中fatal error: stdio.h: 没有那个文件或目录的错误的解决方法
- 错误信息could not resolve property: xxx of: pojo.xxxx
- StackOverflow程序员推荐:每个程序员都应读的30本书
- iOS_基于百度地图的开发
- Codefoeces 3A. Shortest path of the king
- 黑马程序员--oc:集合
- liunx vi工具使用
- 黑马程序员--UIiImageView实现动画播放
- weiyi通讯录(二)获取联系人信息包括头像 增删改查功能,
- c#中任务工厂执行多线程任务
- Codeforces 3B. Lorry
- 多尺度视网膜增强算法(MSRCR)
- github版本库使用详细教程(命令行及图形界面版)