poj3278Catch That Cow
| Time Limit: 2000MS | Memory Limit: 65536K | |
| Total Submissions: 88361 | Accepted: 27679 |
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
Output
Sample Input
5 17
Sample Output
4
Hint
Source
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <queue> using namespace std; int que[];
int start=,endd=;
int time[]={};
int vis[]={};
int n,k; int bfs(int n,int k){
memset(que,,sizeof(que));
memset(time,,sizeof(time));
memset(vis,,sizeof(vis));
start=;
endd=;
que[endd++]=n;
vis[n]=;
while(start<endd){
int t=que[start];
start++;
for(int i=;i<;i++){
int tt=t;
if(i==){
tt+=;
}else if(i==){
tt-=;
}else if(i==){
tt*=;
}
if(tt>||tt<){
continue;
}
if(!vis[tt]){
vis[tt]=;
que[endd]=tt;
time[tt]=time[t]+;
if(tt==k){
return time[tt];
}
endd++;
}
}
}
} int main()
{
int ans;
while(~scanf("%d %d",&n,&k)){
if(n<k){
ans=bfs(n,k);
}else{
ans=n-k;
}
printf("%d\n",ans);
}
return ;
}
poj3278Catch That Cow的更多相关文章
- poj3278Catch That Cow(BFS)
Catch That Cow Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 37094 Accepted: 11466 ...
- poj3278-Catch That Cow 【bfs】
http://poj.org/problem?id=3278 Catch That Cow Time Limit: 2000MS Memory Limit: 65536K Total Submis ...
- POJ 3278 Catch That Cow(bfs)
传送门 Catch That Cow Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 80273 Accepted: 25 ...
- 【BZOJ1623】 [Usaco2008 Open]Cow Cars 奶牛飞车 贪心
SB贪心,一开始还想着用二分,看了眼黄学长的blog,发现自己SB了... 最小道路=已选取的奶牛/道路总数. #include <iostream> #include <cstdi ...
- HDU Cow Sorting (树状数组)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2838 Cow Sorting Problem Description Sherlock's N (1 ...
- [BZOJ1604][Usaco2008 Open]Cow Neighborhoods 奶牛的邻居
[BZOJ1604][Usaco2008 Open]Cow Neighborhoods 奶牛的邻居 试题描述 了解奶牛们的人都知道,奶牛喜欢成群结队.观察约翰的N(1≤N≤100000)只奶牛,你会发 ...
- 细读cow.osg
细读cow.osg 转自:http://www.cnblogs.com/mumuliang/archive/2010/06/03/1873543.html 对,就是那只著名的奶牛. //Group节点 ...
- POJ 3176 Cow Bowling
Cow Bowling Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 13016 Accepted: 8598 Desc ...
- raw,cow,qcow,qcow2镜像的比较
在linux下,虚拟机的选择方式有很多,比如vmware for linux,virtual box,还有qemu,在以前,使用qemu的人不多,主要是使用起来有些麻烦,但现在随着Openstack的 ...
随机推荐
- javagc日志详解
https://blog.csdn.net/aliveTime https://plumbr.io/blog/garbage-collection/understanding-garbage-coll ...
- arcgis pro指数库
来自:https://pro.arcgis.com/zh-cn/pro-app/help/data/imagery/indices-gallery.htm 植被和土壤指数 MSAVI “修正土壤调节植 ...
- CSS实现16:9等比例盒子
问题:图片的宽度100%,高度要始终自适应为16:9. 解决方案: 1.通过js程序算出绝对高度再进行设置.这是解决问题最容易想到的方法. 2.但是,我们的原则是能用css实现的功能尽量用css,这有 ...
- python3 读取dbf文件报错 UnicodeDecodeError: 'gbk' codec can't decode
在读取dbf文件时由于编码问题报错:UnicodeDecodeError: 'gbk' codec can't decode byte 0xb5 in position 49: incomplete ...
- 运维笔记10 (Linux软件的安装与管理(rpm,yum))
概述:用rpm安装和管理软件(rpm解决依赖性),用yum安装与管理软件(yum解决依赖性). 1.linux的软件 linux能够说是一款改变时代的操作系统,可是一个操作系统再优秀假设没有好用的应用 ...
- html input 文本框 只能输入数字,包含输小数点.
<input type="text" id="source_tds" name="source_tds" value="&l ...
- Atitit.如何文章写好 论文 文章 如何写好论文 技术博客
Atitit.如何文章写好 论文 文章 如何写好论文 技术博客 1. 原则 1 1.1. 有深度, 有广度 1 1.2. 业务通用性有通用性 尽可能向上抽象一俩层..业务通用性与语言通用性. 2 ...
- [lvs]lvs的三种模式
回顾了下lvs的三种模式的调度机制 1.lvs的dr模式中的arp的抑制,eth用自己口arp回应. 2.keepalive是否直接操作rs? 不直接操作, 只操作dr(配lvs) 3.tunnel模 ...
- 【python】——python3 与 python2 的那些不兼容
python2 python3 string.uppercase string.ascii_uppercase string.lowercase string.ascii_lowercase xran ...
- Sword libcurl回调函数相关知识
libcurl响应回调函数说明 libcurl在默认情况下,回调里面会将数据分段的返回,不会一下子将发送端的数据全部塞到回调函数里面, 经过源码分析回调函数和curl_easy_perform是在 ...