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. SQLAlchemy中时间格式化及将时间戳转成对应时间的方法-mysql

    https://blog.csdn.net/guoqianqian5812/article/details/80175866 方法很简答,都是借助于mysql数据库提供的函数将时间格式化方法 func ...

  2. dhttp与IdCookieManager处理登陆过程

    dhttp与IdCookieManager处理登陆过程 我们知道,用IE注册网页(象论坛)时,它能够自动找出相应的Cookie并提交给服务器,从而使用户不用重新登录就能够看到与他自己帐号有关的内容.这 ...

  3. ORA-00054:resource busy and acquire with nowait specified解决方法

    1.用dba权限的用户查看数据库都有哪些锁 SELECT T2.USERNAME,T2.SID,T2.SERIAL#,T2.LOGON_TIME        FROM V$LOCKED_OBJECT ...

  4. 20165336 2016-2017-2 《Java程序设计》第9周学习总结

    20165336 2016-2017-2 <Java程序设计>第9周学习总结 教材学习内容总结 1.URL类:URL类是java.net包中的一个重要的类,使用URL创建对象的应用程序称作 ...

  5. Linux忘记密码常用的几种解决方法

    原文链接:https://www.cnblogs.com/vurtne-lu/p/6550590.html 一. lilo引导1. 在出现 lilo: 提示时键入 linux single Boot: ...

  6. Servlet (二)ServletContext

    package cn.sasa.serv; import java.io.IOException; import javax.servlet.ServletContext; import javax. ...

  7. 洛谷P3158 放棋子 [CQOI2011] dp+数论

    正解:dp+数论 解题报告: 传送门! 考虑对每种颜色的棋子单独考虑鸭,那显然有,当某一行或某一列已经被占据的时候,那一行/一列就不能再放别的颜色的棋子了,相当于直接把那一行/一列直接消了 显然就能考 ...

  8. 使用jquery.uploadify上传文件

    今天在网上找了一天,想要找到一个比较全的使用案例,结果发现基本上全是一个版本的... 我的问题主要是上传完成后,还需要将路径获取到,然后保存到数据库. 查了一下资料发现有这么一个参数onComplet ...

  9. 分布式文档系统_document查询内部原理

    1.客户端发送请求到任意一个node,成为coordinate node2.coordinate node对document进行路由,将请求转发到对应的node,此时会使用round-robin随机轮 ...

  10. dispatch_queue_set_specific可重入的gcd

    有时候我们很希望知道当前执行的queue是谁,比如UI操作需要放在main queue中执行.如果可以知道当前工作的queue是谁,就可以很方便的指定一段代码操作在特定的queue中执行.这种做法让G ...