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. ODOO权限管理,在两个方面设置权限

    转载参考https://zhuanlan.zhihu.com/p/29130388 在odoo中新建两个用户user1,user2 新建用户 建完了用户,记得编辑用户,设置密码. 然后以user1用户 ...

  2. pandas与sqlalchemy交互实现科学计算

      import pandas as pd import numpy as np from sqlalchemy import create_engine #建立数据库引擎 engine = crea ...

  3. SQL Server的一些小问题

    一.SQL Server远程调用失败 解决办法:在控制面板-程序和功能中卸载“Microsoft SQL Server 2012 Express LocalDB”,具体版本根据你安装的VS版本决定,我 ...

  4. python脚本获取文件的创建于修改日期并计算时间差

    由于在计算一个算法的运行时间的时候,需要将文件的创建日期与修改日期读取到,然后计算两者之差,在网上搜索了相关的程序之后,自己又修改了一下,把代码贴在这里,供以后查阅使用,也希望可以帮到其他人. # - ...

  5. Why does the memory usage increase when I redeploy a web application?

    That is because your web application has a memory leak. A common issue are "PermGen" memor ...

  6. ZedBoard上运行linux系统的准备工作框架

    目标:ZedBoard上运行linux系统. 需要什么:图中上色部分. 应该做哪些工作:上色部分之前的所有步骤. 由上图得知,为了顺利在zedboard上构建嵌入式Linux操作系统,我们一般需要如下 ...

  7. 软件项目管理:什么是baseline

    只要是接触软件的人,都或多或少的需要接触一些软件相关的名词术语.其中baseline也许是大家听得最多,但是却是最模糊的概念. 其中百度百科给出的解释如下 基线(Baseline) 基线是软件文档或源 ...

  8. C++中的内存区域及其性能特征

    首先须要指出的是.我们通经常使用"堆"和"自由存储"这两个术语来区分两种不同类型的动态分配内存. 1.常量数据:常量数据区域主要用于存储字符串以及其它在编译期就 ...

  9. OC照片选择器MJPhotoBrowser

    图片选择器,看cocoachina发现一个有趣的框架,很好用,分享一下,其实做出该功能我之前写过一篇博客,使用转场动画写的,就是图片的手势缩放没写,有兴趣可以看看 效果图: github地址:http ...

  10. Python中使用SMTP发送邮件以及POP收取邮件

    假设我们自己的电子邮件地址是from@163.com,对方的电子邮件地址是to@sina.com(这里的地址虚拟的),现在我们用Outlook或者Foxmail之类的软件写好邮件,填上对方的Email ...