poj1915
来源:互联网 发布:逆战换弹连炮数据 编辑:程序博客网 时间:2024/06/05 00:24
最基础的BFS了吧。。
Source CodeProblem: 1915User: fistyMemory: 936KTime: 141MSLanguage: G++Result: Accepted Source Code #include <cstdio> #include <algorithm> #include <queue> #include <cstring> using namespace std; #define MAX_N 310 const int INF = 0xffff; int d[8][2] = {{1,2},{1,-2},{2,1},{2,-1},{-1,2},{-1,-2},{-2,-1},{-2,1}}; int sx,sy; int gx,gy; int t, n; int dis[MAX_N][MAX_N]; typedef pair<int, int> P; void solve(){ queue <P> que; for(int i = 0;i < n; i++){ for(int j = 0;j < n; j++){ dis[i][j] = INF; } } que.push(P(sx,sy)); dis[sx][sy] = 0; while(que.size()){ P p = que.front(); que.pop(); int x = p.first; int y = p.second; if(x == gx && y == gy) break; for(int i = 0;i < 8; i++){ int dx = x + d[i][0]; int dy = y + d[i][1]; if(dx >= 0 && dx < n && dy < n && dy>= 0 && dis[dx][dy] == INF) { que.push(P(dx, dy)); dis[dx][dy] = dis[x][y] + 1; } } } printf("%d\n", dis[gx][gy]); } int main(){ scanf("%d", &t); while(t--){ scanf("%d", &n); scanf("%d%d", &sx, &sy); scanf("%d%d", &gx, &gy); solve(); } return 0; }
0 0
- POJ1915
- poj1915
- poj1915
- poj1915
- POj1915
- POJ1915
- poj1915
- HDU1372&&POJ1915
- poj1915 BFS
- poj1915 bfs
- POJ1915 BFS
- poj1915 & poj2243 Knight Moves
- poj1915 Knight Moves
- poj1915 - Knight Moves
- POJ1915 经典bfs
- (未)poj1915(bfs)
- poj2243+poj1915骑士问题
- POJ1915:Knight Moves(BFS)
- swift-控制语句测试题答案
- 设置图片圆角
- ORACLE 操作和管理表
- oc 沙盒目录定位与文件操作 (1)
- [leetcode] Median of Two Sorted Arrays
- poj1915
- 如何学好3D游戏引擎编程(二)
- hdu 3605 Escape(多重匹配)
- LCA
- C#调用C(C++)dll示例教程,包含dll找不到函数入口的解决办法,包含C#dll调用方式不对出错的解决办法
- ORACLE 操纵数据&&锁&&事务
- 如何学好3D游戏引擎编程(三)
- POJ3278
- C与C++混编所遇到的问题