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 ...
随机推荐
- 解决python logging重复写日志问题
import logging from homework.exam_homework_0413.common import contants from homework.exam_homework_0 ...
- win7系统标准用户恢复administrator账号方法
一次误操作,把管理员账号给禁用了,满眼的泪花~~~~~~~~~ 标准用户,什么都干不了,怎么办呢????? 度娘一下,各种奇葩答案,就是解决不了 呵呵,最后找到了解决方法: 1.开机后BIOS过后,按 ...
- innodb_flush_log_at_trx_commit与sync_binlog理解
innodb_flush_log_at_trx_commit该参数控制重做日志写入磁盘的过程.我们知道 InnoDB 使用“Write Ahead Log”策略来避免数据丢失问题,即依靠重做日志来保证 ...
- java中mysql查询报错java.sql.SQLException: Before start of result set
异常:java.sql.SQLException: Before start of result set 解决方法:使用rs.getString();前一定要加上rs.next(); sm = con ...
- 100-days: twenty-seven
Title: Criticism for China's child modeling(代指从事模特行业的人) industry after video of 3-year-old being kic ...
- 监控服务器配置(一)-----Prometheus安装配置
最近和朋友一起做的监控配置,拿出来共享一下 1.下载prometheus安装包(linux版)到 /opt/minitor/prometheus . 下载地址:https://download.csd ...
- distpicker使用记录
今天使用distpicker遇到了一些问题,记录一下. 插件地址 使用说明 需要引入的 js 文件 <script type="text/javascript" src=&q ...
- vue 增删改查
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...
- 1、背景介绍及移动云MAS平台 --短信平台
目的: 刚开发完成一套短信平台以及一个Web端短信发送系统,短信平台耗时两个周.短信发送系统耗时两个多月,开发使用的技术没什么高科技含量,在此主要是记录下很多情况的处理方案,希望能让大家提出改善方案和 ...
- Springmvc中@RequestMapping 属性用法归纳
简介: @RequestMapping RequestMapping是一个用来处理请求地址映射的注解,可用于类或方法上.用于类上,表示类中的所有响应请求的方法都是以该地址作为父路径. RequestM ...