(广搜)Catch That Cow -- poj -- 3278
链接:
http://poj.org/problem?id=3278
| Time Limit: 2000MS | Memory Limit: 65536K | |
| Total Submissions: 62113 | Accepted: 19441 |
Description
Farmer John has been informed of the location of a fugitive cow and wants to catch her immediately. He starts at a point N (0 ≤ N ≤ 100,000) on a number line and the cow is at a point K (0 ≤ K ≤ 100,000) on the same number line. Farmer John has two modes of transportation: walking and teleporting.
* Walking: FJ can move from any point X to the points X - 1 or X + 1 in a single minute
* Teleporting: FJ can move from any point X to the point 2 × X in a single minute.
If the cow, unaware of its pursuit, does not move at all, how long does it take for Farmer John to retrieve it?
Input
Output
Sample Input
5 17
Sample Output
4
Hint
代码:
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <algorithm>
#include <queue> using namespace std; #define N 110000 struct node
{
int x, step;
}; int s, e;
bool vis[N]; int BFS(int s)
{
node p, q;
p.x = s, p.step = ; memset(vis, false, sizeof(vis));
vis[s] = true;
queue<node>Q;
Q.push(p); while(Q.size())
{
p = Q.front(), Q.pop(); if(p.x == e) return p.step; for(int i=; i<; i++)
{
if(i==)
q.x = p.x + ;
else if(i==)
q.x = p.x - ;
else if(i==)
q.x = p.x * ; q.step = p.step + ;
if(q.x>= && q.x<N && !vis[q.x])
{
Q.push(q);
vis[q.x] = true;
}
}
} return -;
} int main()
{
while(scanf("%d%d", &s, &e)!=EOF)
{
int ans = BFS(s); printf("%d\n", ans);
}
return ;
}
(广搜)Catch That Cow -- poj -- 3278的更多相关文章
- catch that cow POJ 3278 搜索
catch that cow POJ 3278 搜索 题意 原题链接 john想要抓到那只牛,John和牛的位置在数轴上表示为n和k,john有三种移动方式:1. 向前移动一个单位,2. 向后移动一个 ...
- Catch That Cow POJ - 3278 [kuangbin带你飞]专题一 简单搜索
Farmer John has been informed of the location of a fugitive cow and wants to catch her immediately. ...
- Catch That Cow POJ - 3278 bfs map超时,短路判断顺序。
题意:可以把n边为n+1,n-1,n*2问从n到k的最少变化次数. 坑:标题写了.有点不会写bfs了... ac代码 #define _CRT_SECURE_NO_WARNINGS #include& ...
- C - Catch That Cow POJ - 3278
//标准bfs #include <iostream> #include <cstdio> #include <algorithm> #include <cm ...
- kuangbin专题 专题一 简单搜索 Catch That Cow POJ - 3278
题目链接:https://vjudge.net/problem/POJ-3278 题意:人可以左移动一格,右移动一格,或者移动到当前位置两倍下标的格子 思路:把题意的三种情况跑bfs,第一个到达目的地 ...
- (广搜)Dungeon Master -- poj -- 2251
链接: http://poj.org/problem?id=2251 Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 2137 ...
- poj 3278:Catch That Cow(简单一维广搜)
Catch That Cow Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 45648 Accepted: 14310 ...
- poj 3278 Catch That Cow (广搜,简单)
题目 以前做过,所以现在觉得很简单,需要剪枝,注意广搜的特性: 另外题目中,当人在牛的前方时,人只能后退. #define _CRT_SECURE_NO_WARNINGS //这是非一般的最短路,所以 ...
- POJ 3278 Catch That Cow(BFS,板子题)
Catch That Cow Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 88732 Accepted: 27795 ...
随机推荐
- hudson插件说明
Artifactory Plugin:maven仓库管理工具 Backup plugin 可以备份hudson_home下所有文件,除了svncode.这个插件有问题,不能使用. Build Publ ...
- SpringMVC+hibernate4事务处理
首先spring-hibernate.xml里配置事务: <!-- 配置事务管理器 --> <bean id="transactionManager" class ...
- mysql-10临时表、复制表
1.创建临时表 mysql临时表在我们需要保存一些临时数据时非常有用. 临时表只在当前连接可见,当关闭连接时,mysql会自动删除表并释放所有空间. 如果使用客户端创建临时表,只有在管不客户端程序时才 ...
- 利用PHP实现页面跳转同时POST传参,CURL不行
function payto(){ echo "<form style='display:none;' id='form1' name='form1' method='post' ac ...
- Lucene 中的Tokenizer, TokenFilter学习
lucene中的TokenStream,TokenFilter之间关系 TokenStream是一个能够在被调用后产生语汇单元序列的类,其中有两个类型:Tokenizer和TokenFilte ...
- oracle to_date函数和mysql DATE_FORMAT函数用法
一.在Oracle中,当想把字符串为‘2011-09-20 08:30:45’的格式转化为日期格式,我们可以使用oracle提供的to_date函数. sql语句为: SELECT to_date(' ...
- linux命令killall 、kill 、pkill 命令详解
转自:http://www.cnblogs.com/rsky/p/4886043.html killall 命令 Linux系统中的killall命令用于杀死指定名字的进程(kill processe ...
- 十二.jQuery源码解析之.eq().first().last().slice()
eq(index):将集合中的索引为index的元素提取出来. first():返回集合中的第一个元素. .last():防护集合中的最后一个元素. .slice(start[,end]):返回集合中 ...
- CVE-2018-8420 漏洞复现
影响的 Windows 版本: Microsoft Windows 10 Version 1607 for 32-bit SystemsMicrosoft Windows 10 Version 160 ...
- http中的Content-Type
要学习content-type,必须事先知道它到底是什么,是干什么用的. HTTP协议(RFC2616)采用了请求/响应模型.客户端向服务器发送一个请求,请求头包含请求的方法.URI.协议版本.以及包 ...