<span style="color:#330099;">/*
A - 广搜 基础
Time Limit:2000MS Memory Limit:65536KB 64bit IO Format:%I64d & %I64u
Submit Status
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
Line 1: Two space-separated integers: N and K
Output
Line 1: The least amount of time, in minutes, it takes for Farmer John to catch the fugitive cow.
Sample Input
5 17
Sample Output
4
Hint
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.
By Grant Yuan
2014.7.13
*/
#include<iostream>
#include<stdio.h>
#include<string.h>
#include<queue>
#include<cstdio>
using namespace std;
bool a[100003];
typedef struct{
int num;
int sum;
}dd;
queue<dd>q;
int n,k;
int res;
void slove()
{int m,count;
int x;
dd init;
while(!q.empty()){ if(q.front().num==n)
{ res=q.front().sum;
break;
} m=q.front().num;
count=q.front().sum;
x=m-1;
if(a[x]==0)
{ init.num=x;
init.sum=count+1;
q.push(init);
a[x]=1;
} x=m+1;
if(a[x]==0)
{
init.num=x;
init.sum=count+1;
q.push(init);
a[x]=1; } if(m%2==0){
x=m/2;
if(a[x]==0)
{
init.num=x;
init.sum=count+1;
q.push(init);
a[x]=1;
}}
q.pop();}
} int main()
{
scanf("%d%d",&n,&k);
memset(a,0,sizeof(a));
dd init;
init.num=k;
init.sum=0;
a[k]=1;
q.push(init);
slove();
cout<<res<<endl;
return 0;
} </span>

A广搜的更多相关文章

  1. HDU--杭电--1195--Open the Lock--深搜--都用双向广搜,弱爆了,看题了没?语文没过关吧?暴力深搜难道我会害羞?

    这个题我看了,都是推荐的神马双向广搜,难道这个深搜你们都木有发现?还是特意留个机会给我装逼? Open the Lock Time Limit: 2000/1000 MS (Java/Others)  ...

  2. HDU 5652(二分+广搜)

    题目链接:http://acm.hust.edu.cn/vjudge/contest/128683#problem/E 题目大意:给定一只含有0和1的地图,0代表可以走的格子,1代表不能走的格 子.之 ...

  3. nyoj 613 免费馅饼 广搜

    免费馅饼 时间限制:1000 ms  |  内存限制:65535 KB 难度:3   描述 都说天上不会掉馅饼,但有一天gameboy正走在回家的小径上,忽然天上掉下大把大把的馅饼.说来gameboy ...

  4. poj 3984:迷宫问题(广搜,入门题)

    迷宫问题 Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 7635   Accepted: 4474 Description ...

  5. poj 3278:Catch That Cow(简单一维广搜)

    Catch That Cow Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 45648   Accepted: 14310 ...

  6. 双向广搜 POJ 3126 Prime Path

      POJ 3126  Prime Path Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 16204   Accepted ...

  7. 广搜+打表 POJ 1426 Find The Multiple

    POJ 1426   Find The Multiple Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 25734   Ac ...

  8. 双向广搜 codevs 3060 抓住那头奶牛

    codevs 3060 抓住那头奶牛 USACO  时间限制: 1 s  空间限制: 16000 KB  题目等级 : 黄金 Gold   题目描述 Description 农夫约翰被告知一头逃跑奶牛 ...

  9. 双向广搜+hash+康托展开 codevs 1225 八数码难题

    codevs 1225 八数码难题  时间限制: 1 s  空间限制: 128000 KB  题目等级 : 钻石 Diamond   题目描述 Description Yours和zero在研究A*启 ...

  10. UVa12726 one Friend at a Time (位 广搜)

    题目链接:UVa12726 是个PDF,不好复制进来. 大意:有个人要追个妹子,想加妹子QQ,但是不知道谁规定的,玩QQ的人要加好友必须先要有至少k个共同好友.共有N个人玩QQ,编号为1到N,1是男主 ...

随机推荐

  1. 配置文件:android:inputType参数类型说明

    输入字符 android:inputType="none"  --输入普通字符  android:inputType="text" --输入普通字符  andr ...

  2. consul windows下搭建

    起源 由于项目在linux部署,但是开发和测试是在windows下的,所以,暂时接触到consul,暂时也不会远程连接,只好在windows下安装consul 过程 去官网下载:https://www ...

  3. 源码阅读-Kingfisher

    最后更新:2018-01-16 使用教程: 官方的链接 使用 Kingfisher 处理网络图片的读取与缓存 1. 开始使用 桥接 KingFisher, 利用 KingfisherCompatibl ...

  4. Jar包方式运行web项目

    使用Maven进行打包 在自己的电脑终端中进入到pom.xml文件的目录中执行maven打包.命令为: mvn clean package 1 成功的标志为​上面显示BUILD SUCCESS成功打包 ...

  5. eclipse连接Mysql和测试

    一.前期准备: 1.eclipse 2.Mysql workbench 3.jdbc 下载地址:https://www.mysql.com/products/connector/ 点击JDBC Dri ...

  6. php curl http digest

    php用curl访问有http digest验证的网址时,不能直接加在URL上,例如: http://user:pass@xxx.xxx.xxx.xxx/index.php?a=1&b=2 这 ...

  7. nginx中lua主动设置Content-Length

    最近发现lua调用ngx.say和ngx.print 默认返回的HTTP头是trunk模式的,通常情况下是很好的,没有什么问题:但是要提供给其他人回源的时候就有问题了,特别是我要给slice模块回源, ...

  8. 3D聚类

    1 3D聚类和普通的二维聚类实质一样,只不过维数太高了,用三维图来表示了. 下面将官网的改成只生成一个图了 #!/usr/bin/python # -*- coding:utf-8 -*- print ...

  9. 算法初级(scala)

    来源:力扣(LeetCode)链接:https://leetcode-cn.com/problems/two-sum 1.给定一个整数数组 nums 和一个目标值 target,请你在该数组中找出和为 ...

  10. 【ABAP系列】SAP ABAP 行列转换的方法

    公众号:SAP Technical 本文作者:matinal 原文出处:http://www.cnblogs.com/SAPmatinal/ 原文链接:[ABAP系列]SAP ABAP 行列转换的方法 ...