POJ3278
来源:互联网 发布:逆战换弹连炮数据 编辑:程序博客网 时间:2024/05/22 08:09
一维数组上的BFS 下一个状态点分别是 x-1, x + 1, 2 * x. x-1 之后需要判断是否小于0来剪枝
Source CodeProblem: 3278User: fistyMemory: 1512KTime: 47MSLanguage: G++Result: Accepted Source Code #include <cstdio> #include <string> #include <queue> using namespace std; int s,g; #define MAX_N 200030 #define INF 0xffff int dx[2] = {-1, 1}; int d[MAX_N]; void solve(){ queue<int> que; fill(d, d + MAX_N, INF); que.push(s); d[s] = 0; while(que.size()){ int x = que.front(); que.pop(); if(x == g) break; for(int i = 0;i < 3; i++){ int nx; if(i == 2){ nx = x*2; }else{ nx = x + dx[i]; } if(nx > MAX_N || nx < 0) continue; if(d[nx] == INF ){ que.push(nx); d[nx] = d[x] + 1; } } } printf("%d\n", d[g]); } int main(){ while(scanf("%d%d", &s, &g) != EOF){ solve(); } return 0; }
0 0
- POJ3278
- POJ3278
- POJ3278
- poj3278
- poj3278
- poj3278
- POJ3278
- POJ3278
- poj3278
- poj3278
- poj3278
- POJ3278
- poj3278
- poj3278
- poj3278
- poj3278
- POJ3278
- POJ3278
- hdu 3605 Escape(多重匹配)
- LCA
- C#调用C(C++)dll示例教程,包含dll找不到函数入口的解决办法,包含C#dll调用方式不对出错的解决办法
- ORACLE 操纵数据&&锁&&事务
- 如何学好3D游戏引擎编程(三)
- POJ3278
- C与C++混编所遇到的问题
- Windows下配置Storm源码阅读环境(vim+ctags)
- Java关键字----transient
- mount参数
- 安装VS2010 SP1失败,安装VS2010 SP1时出现回滚,
- git clone简介
- Linux内核设计与实现(十二)——内存管理
- 维基oi 1214 线段覆盖