- poj3278 Catch That Cow
- 1.题目描述
- 2.输入要求
- 3.输出要求
- 4.题目解释
- 5.测试样例
- 6.代码
- poj1426 Find The Multiple
- 1.题目描述
- 2.输入要求
- 3.输出要求
- 4.题目解释
- 5.测试样例
- 6.代码
题目链接:https://vjudge.net/problem/POJ-3278
1.题目描述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?
2.输入要求Line 1: Two space-separated integers: N and K
3.输出要求Line 1: The least amount of time, in minutes, it takes for Farmer John to catch the fugitive cow.
4.题目解释农夫约翰已被告知一头逃犯的位置,并希望立即将其抓住。他开始于一个点Ñ(0≤ Ñ在数轴上≤100,000)和母牛是在点ķ(0≤ ķ上相同数目的线≤100,000)。农夫约翰有两种运输方式:步行和传送。
行走:FJ可以在一分钟内从任意点X移至点X -1或X + 1。 传送:FJ可以在一分钟内从任意点X移至点2× X。
如果没有意识到它的追捕能力的母牛完全没有动弹,那么农夫约翰要花多长时间才能找回它?
5.测试样例Sample Input
5 17
Sample Output
4
6.代码
#include
#include
#include
using namespace std;
//n,k最大为100000
#define N 200001
bool visit[N];
int n,k;
//结构体,点和步数
struct node{
int id;
int step;
};
//广度优先遍历
int bfs(int n,int k)
{
queue q;
node f;
//初始化
f.id = n;
f.step = 0;
visit[n] = true;
q.push(f);
while(!q.empty())
{
node now = q.front();
q.pop();
if(now.id==k) return now.step;
//分别遍历三种情况
node next;
for(int i=0;i>n>>k;
memset(visit,false,sizeof(visit));
cout
关注
打赏
最近更新
- 深拷贝和浅拷贝的区别(重点)
- 【Vue】走进Vue框架世界
- 【云服务器】项目部署—搭建网站—vue电商后台管理系统
- 【React介绍】 一文带你深入React
- 【React】React组件实例的三大属性之state,props,refs(你学废了吗)
- 【脚手架VueCLI】从零开始,创建一个VUE项目
- 【React】深入理解React组件生命周期----图文详解(含代码)
- 【React】DOM的Diffing算法是什么?以及DOM中key的作用----经典面试题
- 【React】1_使用React脚手架创建项目步骤--------详解(含项目结构说明)
- 【React】2_如何使用react脚手架写一个简单的页面?