poj 3278 bzoj 1646: [Usaco2007 Open]Catch That Cow 抓住那只牛(BFS)
1646: [Usaco2007 Open]Catch That Cow 抓住那只牛
Time Limit: 5 Sec Memory Limit: 64 MB
Submit: 1223 Solved: 583
[Submit][Status][Discuss]
Description
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
Sample Output
搜索入门经典题
其实就是暴力
#include<stdio.h>
#include<string.h>
#include<queue>
using namespace std;
typedef struct
{int x;int time;
}state;
state now, temp;
queue<state> q;
int flag[150005];
int main(void)
{int n, m;while(scanf("%d%d", &n, &m)!=EOF){if(n>=m){printf("%d\n", n-m);continue;}memset(flag, 0, sizeof(flag));now.x = n, now.time = 0;q.push(now);flag[n] = 1;while(q.empty()==0){now = q.front();q.pop();if(now.x==m){while(q.empty()==0)q.pop();break;}if(now.x*2<=150000 && flag[now.x*2]==0){temp.x = now.x*2;temp.time = now.time+1;flag[temp.x] = 1;q.push(temp);}if(now.x-1>0 && flag[now.x-1]==0){temp.x = now.x-1;temp.time = now.time+1;flag[temp.x] = 1;q.push(temp);}if(now.x+1<=100000 && flag[now.x+1]==0){temp.x = now.x+1;temp.time = now.time+1;flag[temp.x] = 1;q.push(temp);}}printf("%d\n", now.time);}return 0;
}
poj 3278 bzoj 1646: [Usaco2007 Open]Catch That Cow 抓住那只牛(BFS)相关推荐
- BZOJ 1646: [Usaco2007 Open]Catch That Cow
题目链接:http://www.lydsy.com/JudgeOnline/problem.php?id=1646 这道题我刚开始就直接硬生生地广搜,然后妥妥地TLE了,后来乖乖地加了一些剪枝... ...
- Catch That Cow抓住那只奶牛(BFS,广度优先搜索)
# **Catch That Cow(抓住那只奶牛)** [题意]:农场主要去追一直逃跑的牛,每次移动有三种选择,位置加一,位置减一,位置乘二,要找到最快的方法让农夫追到牛(也就是移动的次数最少,这个 ...
- Catch That Cow(抓住那头牛C++)
Catch That Cow Farmer John has been informed of the location of a fugitive cow and wants to catch he ...
- poj 3268 bzoj 1631: [Usaco2007 Feb]Cow Party(最短路)
1631: [Usaco2007 Feb]Cow Party Time Limit: 5 Sec Memory Limit: 64 MB Submit: 855 Solved: 613 [Subm ...
- Catch That Cow(农夫和牛)(BFS入门)(详解)
题目: 题目大意: 输入n和k表示农夫和牛的位置,n和k在区间[0,100000]间 农夫有三种方式进行移动,每种方式需要的时间相同,都是一分钟 1.向前移动一米(+1) 2.向后移动一米(-1) 3 ...
- C - Catch That Cow POJ - 3278
C - Catch That Cow POJ - 3278 首先是大暴搜+最优化剪枝(当当前搜索情况不如已有答案优时,返回) #include<cstdio> #include<al ...
- POJ 3278 Catch That Cow
Catch That Cow Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 30924 Accepted: 9536 D ...
- POJ 3278 Catch That Cow BFS
Catch That Cow Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 32071 Accepted: 9866 D ...
- POJ 3278 Catch That Cow(BFS)
题目网址:http://poj.org/problem?id=3278 题目: Catch That Cow Time Limit: 2000MS Memory Limit: 65536K Tot ...
最新文章
- 动态代理及工厂的简单实现
- Elasticsearch技术解析与实战(五)Document解析
- 分析Java核心转储
- SSH中一些典型的问题
- php基本类,php入门一之十大基本类型
- mysql示例employees数据库
- jquery html app,jquery .html()vs .append()
- lopatkin俄大神精简中文系统Windows 10 Pro 19041.21 20H1 Release x86-x64 ZH-CN SMS
- vue 安装 axios
- html5 后端模板 免费,推荐12个非常不错而且免费的后台管理HTML模板
- JAVA——斐波那契数列(递归)
- 微信服务号添加小程序
- Halcon学习之缺陷检测-凸点检测
- Riverbed破解数字性能密码,引领云时代数字变革
- 根据关键词采集文章(按关键词采集数据)
- 使用主题背景编辑器设计应用主题背景
- egg项目部署及PM2的使用
- SystemVerilog学习笔记1 ---《数据类型》
- 13年android手机top,2013年1月安卓热门机型Top20
- Android实现车辆检测(含Android源码 可实时运行)
热门文章
- 在哪里学python-在合肥哪里可以学Python
- python安装-在Python中安装包的三种方法
- python怎么读取csv文件-python如何读取csv数据
- python100例详解-Python编程之属性和方法实例详解
- MATLAB语音识别
- ZS语音识别(智能语音识别工具)V1.3 绿色版
- woocommerce产品选项描述修改_简历修改服务:中文修改、英文修改、中英互译、简历定制,名师一对一指导修改!...
- JavaScript创建页面节点
- SpringBoot 集成log4j2
- Vue动态权限路由addRoutes执行初次白屏解决方法。