Catch That Cow

bfs代码

#include<cstdio>
#include<cstring>
#include<algorithm>
#include<iostream>
#include<string>
#include<vector>
#include<stack>
#include<bitset>
#include<cstdlib>
#include<cmath>
#include<set>
#include<list>
#include<deque>
#include<map>
#include<queue>
using namespace std;
typedef long long lint;
const double PI = acos(-1.0);
const int INF = ;
const int maxn = ; struct node{
int n, t;
}; node n;
int s, e;
int vis[maxn]; int bfs()
{
queue<node>q;
q.push(n);
while(!q.empty())
{
int b[];
node tmp;
tmp = q.front();
q.pop();
// cout << tmp.n << "&&" << tmp.t << " ";
if(tmp.n == e)
{
return tmp.t;
}
for(int i = ; i < ;i++)
{
if(i == ) b[i] = tmp.n - ;
else if(i == ) b[i] = tmp.n + ;
else if(i == ) b[i] = tmp.n * ;
if(b[i] < maxn && !vis[b[i]] && b[i] >= )
{
node g;
g.n = b[i];
g.t = tmp.t + ;
vis[g.n] = ;
q.push(g);
}
}
}
return -;
} int main()
{
while(cin >> s >> e)
{
n.n = s, n.t = ;
memset(vis, , sizeof(vis));
int ans = bfs();
cout << ans << endl;
} }

Catch That Cow (bfs)的更多相关文章

  1. HDU 2717 Catch That Cow (bfs)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2717 Catch That Cow Time Limit: 5000/2000 MS (Java/Ot ...

  2. POJ 3278 Catch That Cow(bfs)

    传送门 Catch That Cow Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 80273   Accepted: 25 ...

  3. HDU 2717 Catch That Cow(BFS)

    Catch That Cow Farmer John has been informed of the location of a fugitive cow and wants to catch he ...

  4. Catch That Cow(BFS)

    Catch That Cow Time Limit: 5000/2000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)To ...

  5. POJ3279 Catch That Cow(BFS)

    本文来源于:http://blog.csdn.net/svitter 意甲冠军:给你一个数字n, 一个数字k.分别代表主人的位置和奶牛的位置,主任能够移动的方案有x+1, x-1, 2*x.求主人找到 ...

  6. ***参考Catch That Cow(BFS)

    Catch That Cow Time Limit : 4000/2000ms (Java/Other)   Memory Limit : 131072/65536K (Java/Other) Tot ...

  7. poj 3278(hdu 2717) Catch That Cow(bfs)

    Catch That Cow Time Limit: 5000/2000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)To ...

  8. 题解报告:hdu 2717 Catch That Cow(bfs)

    Problem Description Farmer John has been informed of the location of a fugitive cow and wants to cat ...

  9. poj 3278 Catch That Cow (bfs)

    题目:http://poj.org/problem?id=3278 题意: 给定两个整数n和k 通过 n+1或n-1 或n*2 这3种操作,使得n==k 输出最少的操作次数 #include<s ...

随机推荐

  1. 查找->静态查找表->分块查找(索引顺序表)

    文字描述 分块查找又称为索引顺序查找,是顺序查找的一种改进方法.在此查找算法中,除表本身外, 还需要建立一个”索引表”.索引表中包括两项内容:关键字项(其值为该字表内的最大关键字)和指针项(指示该子表 ...

  2. ORACLE DB体系结构

    . 实例:一组oracle后台进程.线程以及一个共享内存区. 连接:用户进程和实例之间的通信 会话:用户通过用户进程与实例建立的特定连接 参数文件:包含控制文件的位置和名称 分为pfile和spfil ...

  3. c++ 如何获取多线程的返回值?(std::thread ,std::async)

    //简单的 c++11 线程,简单方便,成员函数随便调用,非成员函数也一样,如需要获取返回时,请自行使用条件变量 std::thread run([&](){ //执行一些耗时的操作 retu ...

  4. 常用的shell脚本(安全方向)

    更多shell脚本参考:https://blog.51cto.com/zero01/2046242 1.拒绝密码撞库攻击的ip shell脚本:实现对登录主机失败10次以上的ip进行拒绝登录 #! / ...

  5. 前端 HTML body标签相关内容

    想要在网页上展示出来的内容一定要放在body标签中. 常用标签: 标题标签 h1-h6 段落标签 p标签 超链接标签 a标签 列表标签 ul,ol,li 定义列表<dl> 子标签 div ...

  6. PixelRatio使用

    export default class PixelRatioView extends Component { render() { return ( <View style={styles.c ...

  7. Tomcat7目录结构详解

    1.bin:该目录下存放的是二进制可执行文件,如果是安装版,那么这个目录下会有两个exe文件:tomcat6.exe.tomcat6w.exe,前者是在控制台下启动Tomcat,后者是弹出UGI窗口启 ...

  8. HBase单机模式安装

    第一部分 安装前准备 1.安装hadoop 今天刚刚学了hbase的一点基础,准备安装Hbase实际操练一下.因为安装hbase的前提条件是已经成功安装了hadoop,而且hadoop的版本要和hba ...

  9. 282A

    #include <iostream> #include <string> using namespace std; int main() { int n, plus, sub ...

  10. nginx命令行参数

    通过控制台进入nginx目录后 1. 启动nginx start nginx 或 nginx.exe 2. 重启nginx nginx -s reload 3. 停止nginx nginx -s st ...