Catch That Cow(BFS)
Catch That Cow
Time Limit: 5000/2000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 10166 Accepted Submission(s): 3179
* 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?
The fastest way for Farmer John to reach the fugitive cow is to move along the following path: 5-10-9-18-17, which takes 4 minutes.
#include <cstdio>
#include <iostream>
#include <queue>
#include <cstring>
using namespace std;
int b,e;
int Mintim;
struct node
{
int pos,t;
}k,tem;
int vis[+];
queue<node> s;
void bfs()
{
while(!s.empty())
s.pop();
k.pos=b,k.t=;
s.push(k);
while(!s.empty())
{
k=s.front();
s.pop();
if(k.pos==e)
{
Mintim=k.t;
return;
}
if(k.pos<||k.pos>||vis[k.pos]) continue;
vis[k.pos]=;
tem.t=k.t+;
tem.pos=k.pos+;
s.push(tem);
tem.pos=k.pos-;
s.push(tem);
tem.pos=k.pos*;
s.push(tem);
}
}
int main()
{
int i,j;
freopen("in.txt","r",stdin);
while(scanf("%d%d",&b,&e)!=EOF)
{
memset(vis,,sizeof(vis));
bfs();
printf("%d\n",Mintim);
}
return ;
}
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 ...
- 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 ...
- Catch That Cow (bfs)
Catch That Cow bfs代码 #include<cstdio> #include<cstring> #include<algorithm> #inclu ...
- 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 ...
随机推荐
- iOS高仿城觅-感谢大神分享
项目展示,由于没有数据,所以所有的cell显示的都是我自己写的数据 抽屉 首页部分效果 首页效果 部分效果 发现 消息 搜索 设置 模糊效果 代码注释展示 代码注释展示 还有很多细节就不一一展示了,大 ...
- HTML5 的段落首行缩进
text-indent:0em;表示当前行不需要缩进,文本顶头开始.这个属性可以用在 div p等元素下面 文本首行的缩进(在首行文字之前插入指定的长度) p { line-height: 2em ...
- Tuning Radio Resource in an Overlay Cognitive Radio Network for TCP: Greed Isn’t Good
好吧,这是09年七月发布在IEEE Communications Magazine的一篇文章. 核心二个词:overlay cognitive radio network,tcp 讲的是,在认知无线网 ...
- httpcomponents-client-4.3.6 HttpPost的简单使用
/** * httpcomponents-client-4.3.6 * @author y */ public class HttpUtil { public static String httpPo ...
- BZOJ1013 球形空间产生器sphere
Description 有一个球形空间产生器能够在n维空间中产生一个坚硬的球体.现在,你被困在了这个n维球体中,你只知道球面上n+1个点的坐标,你需要以最快的速度确定这个n维球体的球心坐标,以便于摧毁 ...
- mybatis常用操作
一.增 1.1 单条 <insert id="addUser" parameterType="com.xxx.model.UserInfo" useGen ...
- 阵列卡,组成的磁盘组就像是一个硬盘,pci-e扩展出sata3.0
你想提升性能,那么组RAID0,主板上的RAID应该是软RAID,肯定没有阵列卡来得稳定.如果你有闲钱,可以考虑用阵列卡. 不会的.即使不能起到RAID的作用,起码也可以当作直接连接了2个硬盘.不会影 ...
- UESTC_小panpan学图论 2015 UESTC Training for Graph Theory<Problem J>
J - 小panpan学图论 Time Limit: 3000/1000MS (Java/Others) Memory Limit: 65535/65535KB (Java/Others) S ...
- LeetCode C++ 解题报告
自己做得LeetCode的题解,使用C++语言. 说明:大多数自己做得,部分参考别人的思路,仅供参考; GitHub地址:https://github.com/amazingyyc/The-Solut ...
- UVALive 6190 Beautiful Spacing (2012 Tokyo regional)
Beautiful Spacing 题意是给一个文本排版,求在满足题目所给要求的条件下,最长连续空格最小是多少. trick: 贪心地模拟是错的,至少无法证明正确性. 正解应该是二分答案+验证. 比较 ...