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. LeetCode 728 Self Dividing Numbers 解题报告

    题目要求 A self-dividing number is a number that is divisible by every digit it contains. For example, 1 ...

  2. word标题自动编号

    1.打开word文档中多级列表->定义新的多级列表 2.根据下图设置级别对应的标题,然后确定

  3. 【Python全栈-后端开发】嵩天老师-Django

    嵩天老师-Python云端系统开发入门教程(Django) 视频地址:https://www.bilibili.com/video/av19801429 课前知识储备: 一.课程介绍: 分久必合.合久 ...

  4. PyQt5学习笔记----标准文件打开保存框QFileDialog

    单个文件打开 QFileDialog.getOpenFileName()多个文件打开 QFileDialog.getOpenFileNames() 文件夹选取     QFileDialog.getE ...

  5. 8.0-uC/OS-III临界段

    1.临界段 (临界段代码,也叫临界区,是指那些必须完整连续运行,不可被打断的代码段) 锁调度器,可以执行ISR,开启调度器不可执行ISR: (1).临界段代码,也称作临界域,是一段不可分割的代码. u ...

  6. Python3学习之路~5.5 sys模块

    用于提供对解释器相关的操作 sys.argv 命令行参数List,第一个元素是程序本身路径 sys.exit(n) 退出程序,正常退出时exit(0) sys.version 获取Python解释程序 ...

  7. python的第三方库

    python的第三方库 https://www.lfd.uci.edu/~gohlke/pythonlibs/

  8. Spark Worker启动Driver和Executor工作流程

    二:Spark Worker启动Driver源码解析 case LaunchDriver(driverId, driverDesc) => { logInfo(s"Asked to l ...

  9. Ext.define细节分析

    自己写的其实还是不懂,再看看别人写的吧Extjs4 源码分析系列一 类的创建过程https://www.cnblogs.com/creazyguagua/p/4302864.htmlhttp://ww ...

  10. Asp.net Core认证和授权:Cookie认证

    关于asp.net core 的文章,博客园已经有很多大牛写过了. 这里我只是记录下自己在学习中的点滴和一些不懂的地方 Cookie一般是用户网站授权,当用户访问需要授权(authorization) ...