POJ 3278.Catch That Cow
来源:互联网 发布:程序员考试考什么 编辑:程序博客网 时间:2024/05/25 05:35
题目:http://poj.org/problem?id=3278
AC代码(C++):
#include <iostream>#include <algorithm>#include <stdio.h>#include <vector>#include <queue>#include <math.h>#include <string>#include <string.h>#include <bitset>#define INF 0xfffffff#define MAXN 100005using namespace std;int n,k;bool vis[MAXN];int dist[MAXN];void bfs() {queue<int> q;memset(vis,false,sizeof(vis));vis[n] = true;q.push(n);int node;while (!q.empty()) {node = q.front();q.pop();if(node==k)return;if(node>0&&vis[node-1]==false){int tmp = node - 1;dist[tmp] = dist[node]+1;vis[tmp] = true;q.push(tmp);}if(node<100000&&vis[node+1]==false){int tmp = node + 1;dist[tmp] = dist[node]+1;vis[tmp] = true;q.push(tmp);}if(2*node<=100000&&vis[node*2]==false){int tmp = node * 2;dist[tmp] = dist[node]+1;vis[tmp] = true;q.push(tmp);}}}int main(){ cin>>n>>k; dist[n] = 0; bfs(); cout<<dist[k];}总结: 很简单的广搜题. 注意不要越界就行.
阅读全文
0 0
- POJ 3278.Catch That Cow
- POJ 3278.Catch That Cow
- Catch That Cow(POJ--
- (poj)Catch That Cow
- Catch That Cow POJ
- Catch That Cow POJ
- Catch That Cow POJ
- Catch That Cow POJ
- Catch That Cow POJ
- Catch That Cow POJ
- 3278. Catch That Cow
- poj 3278 Catch That Cow
- POJ 3278 Catch That Cow
- poj 3278 catch that cow
- poj 3278 Catch That Cow
- POJ 3278 Catch That Cow
- Poj 3278 Catch That Cow
- POJ 3278 Catch That Cow
- MIPI DSI 协议介绍
- Anaconda安装TensorFlow及安装Spyder编译器
- Python排序算法总结
- 程序员必知的8大排序(一)-------直接插入排序,希尔排序(java实现)
- JavaScript工作体系中不可或缺的函数
- POJ 3278.Catch That Cow
- unity ugui手游自适应方法
- Java中使用OpenSSL生成的RSA公私钥进行数据加解密
- Linux下Apache部署503问题
- pthread_mutex_lock的作用
- 项目打包问题
- 公司在什么情况下可以解雇你?(程序员补习法律)
- 基于Java实现Spark统计身高的实例
- C++多态的实现原理