POJ3278 (果bfs)
来源:互联网 发布:c语言长整型定义 编辑:程序博客网 时间:2024/04/28 16:10
RE到死。。。
看了题解才知道忘了剪枝了。。。
比较果的BFS(一开始竟然想成了dfs。。。。菜)
题意:大概是给n,k 将通过将n进行+1,-1,*2的运算求最少需要多上次可以转化为k。
#include <iostream>#include <cstdio>#include <string>#include <queue>#include <algorithm>using namespace std;const int maxn =1e5+10;int vis[maxn];int n,k;int bfs(){ queue<int>que; que.push(n); while(!que.empty()) { int t=que.front();que.pop(); if(t==k) return vis[t]-1; if(t-1>=0&&!vis[t-1]) { vis[t-1]=vis[t]+1; que.push(t-1); } if(t+1<maxn&&!vis[t+1]) { vis[t+1]=vis[t]+1; que.push(t+1); } if(t*2<maxn&&!vis[t*2]) { vis[t*2]=vis[t]+1; que.push(t*2); } }}int main(){ scanf("%d%d",&n,&k); vis[n]=1; int ans=bfs(); printf("%d\n",ans);}
0 0
- POJ3278 (果bfs)
- poj3278(简单的bfs)
- poj3278 抓牛(bfs)
- poj3278 BFS
- POJ3278---bfs
- poj3278 bfs
- poj3278(bfs)
- POJ3278 -- BFS
- POJ3278--BFS
- poj3278-bfs
- POJ3278 BFS
- poj3278 bfs
- POJ3278 BFS
- poj3278 Catch That Cow(bfs搜索)
- poj3278广度优先搜索(BFS)
- POJ3278 Catch That Cow(BFS)
- POJ3278 Catch That Cow(bfs)
- poj3278 Catch That Cow(BFS)
- mysql索引
- cornerstone的安装/打开资源库的方法
- Unity开发环境搭建
- HTML5基础加强css样式篇(background-image径向渐变函数)(四十一)
- WebView与H5那些事儿
- POJ3278 (果bfs)
- VS2016 调用matlab脚本 ——缺少mclmcr.dll
- ELK 记录
- 2017上半年IT技术大会,看看哪一场适合你?
- Jemalloc 初始化(二) index2size和size2index解析
- JSON 应用
- Magento 2.0需要在哪些方面符合中国生态系统?
- git 常用命令整理
- LEETCODE 55. Jump Game