暑假集训(1)第二弹 -----Catch the cow(Poj3278)
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
#include "iostream"
#include "queue" using namespace std;
char a[];
void mset()
{
for (int i=;i<;i++)
a[i] = '';
}
struct far
{
int w;
int step;
};
int bfs(int n,int k)
{
if (n>=k)
return n-k;
queue<far> q;
far fir,sec;
fir.w = n;
fir.step =;
a[n] = '';
q.push(fir);
while (!(q.empty()))
{
sec=q.front();
q.pop();
for (int i=;i<=;i++)
{
switch (i)
{
case : fir.w=sec.w+; break;
case : fir.w=sec.w-; break;
case : fir.w=sec.w*; break;
}
fir.step=sec.step+;
if (fir.w == k) return fir.step;
if (fir.w>= && fir.w<= && a[fir.w] == '' )
{
a[fir.w] ='';
q.push(fir);
}
}
}
}
int main()
{
int n,k;
while (cin>>n>>k)
{
mset();
cout<<bfs(n,k)<<endl;
}
return ;
}
暑假集训(1)第二弹 -----Catch the cow(Poj3278)的更多相关文章
- 2016HUAS暑假集训训练题 B - Catch That Cow
B - Catch That Cow Description Farmer John has been informed of the location of a fugitive cow and w ...
- 暑假集训(4)第二弹 -----递推(hdu2254)
题意概括:上次小A在你的帮助下成功炼成贤者法阵的第一部分——三角分隔,现在他准备绘制法阵的第二部分——莫测矩形. 而他又遇到了一个问题,他不知道不同矩形到底有多少个. 秉持帮人帮到底,送佛送到西的基本 ...
- 暑假集训(3)第二弹 -----Jungle Roads(Hdu1301)
问题梗概:自从上次某个acmer来设计了拉格瑞圣岛的交通路线后,岛上的酋长就相当苦恼,他发现,虽然这些修好的公路便利了岛上的 交通,并且让拉格瑞圣岛的旅游业更加兴旺,甚至他们还收到了一笔不小的国际资金 ...
- 暑假集训(5)第二弹———湫湫系列故事——减肥记I(hdu4508)
问题描述:舔了舔嘴上的油渍,你陷在身后柔软的靠椅上.在德源大赛中获得优胜的你,迫不及待地赶到“吃到饱”饭店吃到饱.当你 正准备离开时,服务员叫住了你,“先生,您还没有吃完你所点的酒菜.”指着你桌上的一 ...
- 暑假集训(2)第二弹 ----- The Suspects(POJ1611)
B - The Suspects Crawling in process... Crawling failed Time Limit:1000MS Memory Limit:20000KB ...
- 抓住那只牛!Catch That Cow POJ-3278 BFS
题目链接:Catch That Cow 题目大意 FJ丢了一头牛,FJ在数轴上位置为n的点,牛在数轴上位置为k的点.FJ一分钟能进行以下三种操作:前进一个单位,后退一个单位,或者传送到坐标为当前位置两 ...
- bfs—Catch That Cow—poj3278
Catch That Cow Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 87152 Accepted: 27344 ...
- 暑假集训(4)第一弹 -----递推(Hdu2039)
题意梗概:fff团团员小A想退团了,不过要退团,他必须绘制出贤者法阵,以证明他有资格不受大fff之灵的监督 并退团,小A他现在要开始收集材料了,但是,他不清楚应该买多少份材料. 虽然你并不想帮他退团, ...
- 暑假集训(5)第一弹——— Super Jumping! Jumping! Jumping!(hdu1087)
题意概括:在上次与娑殚的三次博弈中,你们都取得了胜利.便向娑殚提出要求,借助他的力量,传送到一个安全的地方. 你们的愿望达成了,不过,你和小A似乎失散了. 街上人来人往的特别热闹,每一个人的脸上都洋溢 ...
随机推荐
- string,vector和array(C++ Primer读书笔记)
string string是标准库类型,使用时需要包涵头文件,使用using声明. include <string> using std::string; 1.定义和初始化 string ...
- IntelliJ IDEA的下载、安装和WordCount的初步使用(本地模式和集群模式)
包括: IntelliJ IDEA的下载 IntelliJ IDEA的安装 IntelliJ IDEA中的scala插件安装 用SBT方式来创建工程 或 选择Scala方式来创建工程 本地模式或集群 ...
- javabean以及内省技术详解(转)
一.关于javabean javabean是固定写法的java类 书写格式为: 1)必须有无参构造函数 2)属性必须私有, 我们称为字段 3)提供标准的getter和setter 例: name 字段 ...
- node.js在windows下的学习笔记(1)---安装node.js
1.首先打开http://www.nodejs.org/ 2.选择DOWNLOADS,跳转到下面的画面,我的系统是windows7的32位.所以选择.msi的32bit版本. 3.下载后,得到一个5. ...
- RHCA442学习笔记-Unit10内存地址及分配
Unit 10 Memory Addressing and Allocation 内存地址及分配 学习目标: A. 虚拟地址与物理地 B. 调整内存地址分配 C. 解析内存溢出 10.1 O ...
- 【转】如何优化Cocos2d-X游戏的内存
Published on 2013 年 2 月 4 日, by donglin http://blog.chukong-inc.com/index.php/2013/02/04/%E5%A6%82%E ...
- Java 实现折半查找
package search; import java.util.*; /*折半查找要求线性表是有序的,假设递增 * 基本思路:R[low...high]是当前的查找区间,首先确定中间位置mid=(l ...
- c语言入门经典必背18个程序
1 . /* 输出 9*9 口诀.共 9 行 9 列, i 控制行, j 控制列. */ #include "stdio.h" main() {int i,j,result; fo ...
- 7.Composer的安装和使用
1.安装Composer: 局部安装 要真正获取 Composer,我们需要做两件事.首先安装 Composer (同样的,这意味着它将下载到你的项目中): curl -sS https://getc ...
- C#迭代语句
1,do while语句 do语句重复执行语句或者语句块,直到指定的表达式为false为止.循环体如果为单个语句,可以不放在{}内,如果不是,那么必须放在{}内.如下面的代码 Codeint i=0; ...