poj 3278 bfs
来源:互联网 发布:画板软件哪个好 编辑:程序博客网 时间:2024/04/28 06:38
一开始只开了十万的数组,贡献了几次RE,改为100万后AC
#include <iostream>#include <cstdio>#include <algorithm>#include <queue>#include <cmath>#include <cstring>using namespace std;int mar[1000100];int main(){int n,k;while(scanf("%d%d",&n,&k) == 2){memset(mar,-1,sizeof(mar));mar[n] = 0;queue<int> q; q.push(n); while(!q.empty()) { int a = q.front(); q.pop(); if(a == k && mar[k] != -1) break; if(mar[a-1] == -1 && a-1 < 100100) { mar[a-1] = mar[a] + 1; q.push(a-1); } if (mar[a+1] == -1 && a+1 < 100100) { mar[a+1] = mar[a] + 1; q.push(a+1); } if (mar[2*a] == -1 && 2*a < 100100) { mar[2*a] = mar[a] + 1; q.push(2*a); } } printf("%d", mar[k]);}return 0;}
- POJ 3278 : 经典BFS
- poj 3278 简单bfs
- poj 3278 bfs
- poj 3278、、、BFS
- poj 3278 bfs
- poj-3278-bfs
- poj 3278 bfs
- POJ 3278 BFS
- poj 3278 BFS
- POJ 3278 简单 BFS
- poj 3278 队列+bfs
- poj 3278 (bfs)
- poj 3278(BFS)
- POJ 3278 水BFS
- POJ 3278 BFS水题
- poj 3278 bfs
- poj bfs 3278
- poj 3278 BFS
- 记录
- 修改JBOSS服务器的端口号
- Android实现一个记住密码的登陆界面
- linuxi学习curses(3) 学习输入
- 2013,我来了
- poj 3278 bfs
- iOS ASIHTTPRequest详解
- 面向对象技术
- 【BZOJ1090 || SCOI2003】字符串折叠
- 文件I/O编程学习笔记二(c语言库函数访问文件)
- 磁盘IOPS和带宽(throughput)
- 回归ACm之路
- STM32下载方式
- html--给自己看的