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的 ...
随机推荐
- 7、js对象
在python中我们学习了面向对象,javascript也是一门面向对象语言,在JavaScript中除了null和undefined以外其他的数据类型都被定义成了对象. 本篇导航: String对象 ...
- pygame 笔记-1 按键控制方块移动
背景:家里的娃慢慢长大了,准备教一些儿童入门的编程知识,研究了一阵麻省理工的scratch 2 虽然不错,但是功能有限,很多高级点的东西玩不出来.所以就有了这一系列,先提前自学一下,顺便拿来练手pyt ...
- x264阅读记录-1
x264阅读记录-1 采用x264版本是x264-snapshot-20060316-2245. 1. main函数 x264的main函数位于x264.c中,下面是main函数调用情况: (1)_s ...
- mac下host配置 + mac修改了环境变量却不生效:zsh: command not found: xxx
https://blog.csdn.net/hlllmr1314/article/details/52228672 在/etc/profile中配置了go语言环境变量: export GOROOT=/ ...
- Jetpack 架构组件 Paging 分页加载 MD
Markdown版本笔记 我的GitHub首页 我的博客 我的微信 我的邮箱 MyAndroidBlogs baiqiantao baiqiantao bqt20094 baiqiantao@sina ...
- 微信小程序登录逻辑
wx.getStorage({ key: 'session_id', success: function(res) { //如果本地缓存中有session_id,则说明用户登陆过 console.lo ...
- quartz集群分布式(并发)部署解决方案
项目中使用分布式并发部署定时任务,多台跨JVM,按照常理逻辑每个JVM的定时任务会各自运行,这样就会存在问题,多台分布式JVM机器的应用服务同时干活,一个是加重服务负担,另外一个是存在严重的逻辑问题, ...
- CentOS7本地安装MySQL5.7
操作系统:3.10.0-514.el7.x86_64 安装包:mysql-5.7.25-linux-glibc2.12-x86_64.tar.gz 1:检查是否安装了 libaio(centos7默认 ...
- 找回停掉docker的文件
如果容器还能重启,就restart, 如果状态是DEAD的话, Error response from daemon: Container is marked for removal and cann ...
- Apache-配置、测试和调试
首先执行下面的指令列出有用的Apache配置信息 grep -v '#' /usr/local/apache2/etc/httpd.conf |grep -v '^$' ServerRoot &quo ...