POJ - 3278 Catch That Cow bfs 线性
#include<stdio.h>
#include<string.h>
#include<algorithm>
#include<queue>
using namespace std;
int a[],vis[];
queue<int>q; int bfs(int n,int k)
{
int head,next,i;
q.push(n);
a[n]=;
vis[n]=;
while(q.size()!=)
{
head=q.front();
q.pop();
for(i=;i<;i++)
{
if(i==)next=head-;
else if(i==)next=head+;
else if(i==)next=head*;
if(next>=&&next<=)
{
if(vis[next]==)
{
q.push(next);
a[next]=a[head]+;
vis[next]=;
}
if(next==k)
return a[next];
}
}
} }
int main()
{
int i,j,n,k;
while(scanf("%d%d",&n,&k)!=EOF)
{
memset(a,,sizeof(a));
memset(vis,,sizeof(vis));
while(!q.empty())q.pop();
if(n>=k)
printf("%d\n",n-k);
else
{
printf("%d\n",bfs(n,k));
}
}
return ;
}
POJ - 3278 Catch That Cow bfs 线性的更多相关文章
- POJ - 3278 Catch That Cow BFS求线性双向最短路径
Catch That Cow Farmer John has been informed of the location of a fugitive cow and wants to catch he ...
- POJ 3278 Catch That Cow(BFS,板子题)
Catch That Cow Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 88732 Accepted: 27795 ...
- poj 3278 Catch That Cow (bfs搜索)
Catch That Cow Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 46715 Accepted: 14673 ...
- POJ 3278 Catch That Cow[BFS+队列+剪枝]
第一篇博客,格式惨不忍睹.首先感谢一下鼓励我写博客的大佬@Titordong其次就是感谢一群大佬激励我不断前行@Chunibyo@Tiancfq因为室友tanty强烈要求出现,附上他的名字. Catc ...
- poj 3278 catch that cow BFS(基础水)
Catch That Cow Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 61826 Accepted: 19329 ...
- poj 3278 Catch That Cow bfs
Description Farmer John has been informed of the location of a fugitive cow and wants to catch her i ...
- poj 3278 Catch That Cow(bfs+队列)
Description Farmer John has been informed of the location of a fugitive cow and wants to catch her i ...
- POJ 3278 Catch That Cow bfs 难度:1
http://poj.org/problem?id=3278 从n出发,向两边转移,为了不使数字无限制扩大,限制在2*k以内, 注意不能限制在k以内,否则就缺少不断使用-1得到的一些结果 #inclu ...
- BFS POJ 3278 Catch That Cow
题目传送门 /* BFS简单题:考虑x-1,x+1,x*2三种情况,bfs队列练练手 */ #include <cstdio> #include <iostream> #inc ...
随机推荐
- redis集群搭建及设置账户(转)
Redis集群搭建以及为集群设置密码 介绍安装环境与版本 用两台虚拟机模拟6个节点,一台机器3个节点,创建出3 master.3 salve 环境. redis 采用 redis-3.2.4 版本. ...
- VC++安装及使用
1.在浏览器上下载后不能安装 2.黄振古QQ发原文件,依然不能安装 3.考虑后,想通过360压缩安装 4.浏览器上下载的360压缩大多有病毒,无奈下,删掉鲁大师,下载360安全卫士,通过360下载36 ...
- java之数据库相关
这篇还是在回顾知识.主要是关于java连接Sqlserver2012数据库的一些方式记录,以便以后查询. 十一之内复习完这些知识就可以新学Hibernate啦(*^▽^*) 1.普通方式 注意,在连接 ...
- 基于IDEA工具 lombok 的使用
一.简介 Lombok 是一种 Java™ 实用工具,可用来帮助开发人员消除 Java 的冗长,尤其是对于简单的 Java 对象(POJO).它通过注解实现这一目的. 二.lombok的添加和常用注解 ...
- 3wwang的2019计划
1.探究osg类生物----系列(35天) 已完结 [置顶]探索未知种族之osg类生物[目录]www.3wwang.cn 2.osg中的设计模式---系列(15天) 正在创作... osg中抽象工厂 ...
- 探索未知种族之osg类生物---渲染遍历之裁剪三
前言 在osgUtil::CullVisitor,我们发现apply函数的重载中,有CullVisitor::apply(Group& node),CullVisitor::apply(Swi ...
- hashmap源码研究
概述 在官方文档中是这样描述HashMap的: Hash table based implementation of the Map interface. This implementation pr ...
- matplotlib -- 基础知识
matplotlib 组织图表的方式 最上层是一个 Figure 实例,包含了所有可见的和其他一些不可见的内容.该 Figure 实例包含了一个 Axes 实例的成员属性 Figure.axes,同时 ...
- Intellij IDEA环境配置RestEasy,SpringMVC+RestEasy
在SpringMvc中配置RestEasy,需要以下步骤 1.通过maven导入restEasy所需要的jar包 2.在web.xml文件中添加相应的配置. 3.编写服务. 具体步骤: 1.通过mav ...
- java将word文件转为pdf
import java.io.File; import com.jacob.activeX.ActiveXComponent;import com.jacob.com.Dispatch; public ...