Catch That Cow (bfs)
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)的更多相关文章
- 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 ...
- POJ 3278 Catch That Cow(bfs)
传送门 Catch That Cow Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 80273 Accepted: 25 ...
- 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 ...
- Catch That Cow(BFS)
Catch That Cow Time Limit: 5000/2000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)To ...
- POJ3279 Catch That Cow(BFS)
本文来源于:http://blog.csdn.net/svitter 意甲冠军:给你一个数字n, 一个数字k.分别代表主人的位置和奶牛的位置,主任能够移动的方案有x+1, x-1, 2*x.求主人找到 ...
- ***参考Catch That Cow(BFS)
Catch That Cow Time Limit : 4000/2000ms (Java/Other) Memory Limit : 131072/65536K (Java/Other) Tot ...
- 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 ...
- 题解报告:hdu 2717 Catch That Cow(bfs)
Problem Description Farmer John has been informed of the location of a fugitive cow and wants to cat ...
- 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 ...
随机推荐
- Qt网络模块如何使用(表格)
1.网络模块介绍 类名 说明 中文 QAbstractNetworkCache The interface for cache implementations 缓存实现的接口 QNetworkCach ...
- java之map的基本介绍
map简介 在讲解Map排序之前,我们先来稍微了解下map.map是键值对的集合接口,它的实现类主要包括:HashMap,TreeMap,Hashtable以及LinkedHashMap等.其中这四者 ...
- SQL查询优化:详解SQL Server非聚集索引(转载)
本文是转载,原文地址 http://tech.it168.com/a2011/1228/1295/000001295176.shtml 在SQL SERVER中,非聚集索引其实可以看作是一个含有聚集索 ...
- php获取数据库结构
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...
- MongoDB与关系型数据库 区别
mysql mongodb 表 table Collection 字段 Colum Fields 行 row Document Mongo中的一些概念 ------------- ...
- MySQL 多源复制(Mulit-Source Replication)
MySQL多源复制方案 看复制源Master_1的同步状态:SHOW SLAVE STATUS FOR CHANNEL 'Master_1'\G 查看复制源Master_2的同步状态:S ...
- shell中expect介绍
expect介绍 借助Expect处理交互的命令,可以将交互 过程如:ssh登录,ftp登录等写在一个脚本上,使之自动化完成.尤其适用于需 要对多台服务器执行相同操作的环境中,可以大大提高系统管理人员 ...
- ORM之视图层
1.request对象 前台POST传来的数据,包装到POST字典中request.POST 前台浏览器窗口携带的数据,包装到GET字典中request.GET 前台请求的方式,request.met ...
- ES6语法 promise用法
ES6语法 promise用法 function doSomething(){ return new Promise((resolve,reject)=>{ resolve('jjjj');// ...
- 如何在CentOS 7中安装最新Git(源码安装)
如何在CentOS 7中安装最新Git 2017年05月20日 11:49:53 阅读数:1624 Git是在今天的软件开发行业一个非常有用的版本控制工具.我一直使用Git.于是为Linux公社的读者 ...