http://acm.hdu.edu.cn/showproblem.php?pid=2717

//水搜。。。

 #include<stdio.h>
#include<math.h>
#include<string.h>
#include<stdlib.h>
#include<iostream>
#include<queue>
using namespace std;
struct stu{
int x;
int t;
}abc,q;
int n,k;
int vis[];
void bfs()
{
queue<struct stu>p;
p.push(abc);
while(!p.empty())
{
abc=p.front();
p.pop();
if(abc.x==k)
{
printf("%d\n",abc.t);
return ;
}
q.x=abc.x-;
if(q.x>=&&q.x<=&&!vis[q.x])
{
q.t=abc.t+;
vis[q.x]=;
p.push(q);
}
q.x=abc.x+;
if(q.x>=&&q.x<=&&!vis[q.x])
{
q.t=abc.t+;
vis[q.x]=;
p.push(q);
}
q.x=abc.x*;
if(q.x>=&&q.x<=&&!vis[q.x])
{
q.t=abc.t+;
vis[q.x]=;
p.push(q);
}
}
} int main()
{
//freopen("in.txt","r",stdin);
while(~scanf("%d%d",&n,&k))
{
memset(vis,,sizeof(vis));
abc.x=n;
abc.t=;
vis[n]=;
bfs();
}
return ;
}

hdu2717 Catch That Cow的更多相关文章

  1. HDU2717 Catch That Cow 【广搜】

    Catch That Cow Time Limit: 5000/2000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) T ...

  2. POJ 3278 Catch That Cow(bfs)

    传送门 Catch That Cow Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 80273   Accepted: 25 ...

  3. poj3278 Catch That Cow

    Catch That Cow Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 73973   Accepted: 23308 ...

  4. catch that cow (bfs 搜索的实际应用,和图的邻接表的bfs遍历基本上一样)

    Catch That Cow Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 38263   Accepted: 11891 ...

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

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

  6. 2016HUAS暑假集训训练题 B - Catch That Cow

    B - Catch That Cow Description Farmer John has been informed of the location of a fugitive cow and w ...

  7. 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 ...

  8. BFS POJ 3278 Catch That Cow

    题目传送门 /* BFS简单题:考虑x-1,x+1,x*2三种情况,bfs队列练练手 */ #include <cstdio> #include <iostream> #inc ...

  9. Catch That Cow 分类: POJ 2015-06-29 19:06 10人阅读 评论(0) 收藏

    Catch That Cow Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 58072   Accepted: 18061 ...

随机推荐

  1. 使用inotify检测linux目录内文件变化

    #include <unistd.h> #include <sys/inotify.h> #include <stdio.h> #include <error ...

  2. php 文件上传简单类---限制仅上传jpg文件

    php 文件上传代码,限制只能上传jpg格式文件,也可以自行添加其它扩展名的文件. <?php /* * 图片上传类 仅限JPG格式图片 * edit by www.jbxue.com at 2 ...

  3. 简单的下拉刷新以及优化--SwipeRefreshLayout

    代码工程简要说明:以一个SwipeRefreshLayout包裹ListView,SwipeRefreshLayout接管ListView的下拉事件,若ListView被用户触发下拉动作后,Swipe ...

  4. Android之“Unfortunately,xxx has stopped!”

    初学Android遇到Unfortunately,xxx has stopped!真是一件让人头疼的事情,下面就遇到的两种可能情况给出解决方案.通常遇到的情况在于由一个Activity跳转至另一个Ac ...

  5. python:执行一个命令行N次

    经常希望可以执行一个命令行N次...windows下没有现成的工具(有?推荐给我!) 用python写一个... #!/usr/bin/evn python #coding: utf-8 " ...

  6. Windows Server 2008 HPC 版本介绍以及的Pack

    最近接触了下 这个比较少见的 Windows Server版本 Windows Server 2008 HPC 微软官方的介绍 http://www.microsoft.com/china/hpc/ ...

  7. linux c 打印彩色字符

    #include <stdio.h> #include <string.h> int main(int argc, char **argv) { , j = , str_len ...

  8. 增强的PuTTY 以及 自定义主题

    PuTTY很早之前就没有更新了(0.62),因为都是开源的所以有人branch出来做了增强,如这个PuTTY tray,增加了超链等功能: https://puttytray.goeswhere.co ...

  9. 【quartz】 入门

    把技术债务给还了,首先来一个最简单的demo: 2.x版比1.x有很多改进,1.x基于fw1.2: 2.x基于fw3.5以上:语法上有很大的不同,摒弃了很多1.x的很多东西: 直接以2.x来demo ...

  10. 获取iOS设备的内存状况(转)

    转载自:http://mobile.51cto.com/iphone-285371.htm   iPhone这类移动设备内存有限,而又不能使用交换区,为了不至于导致内存不足而引起运行效率降低或应用崩溃 ...