POJ 3728 Catch That Cow (广搜)
Time Limit: 2000MS | Memory Limit: 65536K | |
Total Submissions: 42564 | Accepted: 13225 |
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<cstdio>
#include<string.h>
#include<iostream>
#include<queue>
#include<algorithm>using namespace std;int vis[100010];
int n,k;struct stu
{int ans;int sum;
};int bfs()
{queue <stu> q;
// while(q.size())
// q.pop();memset(vis,0,sizeof(vis));stu kaishi={n,0};q.push(kaishi);vis[kaishi.ans]=1;while(q.size()){stu xian=q.front();stu xia;q.pop();int i;for(i=0;i<3;i++){if(i==0) xia.ans=xian.ans+1;if(i==1) xia.ans=xian.ans-1;if(i==2) xia.ans=xian.ans*2;xia.sum=xian.sum+1;if(xia.ans==k)return xia.sum;if(xia.ans>=0&&xia.ans<=100010&&!vis[xia.ans]){vis[xia.ans]=1;q.push(xia);}}}return 0;
}int main()
{while(scanf("%d%d",&n,&k)!=EOF){if(n>=k){printf("%d\n",n-k);}elseprintf("%d\n",bfs());}return 0;
}
POJ 3728 Catch That Cow (广搜)相关推荐
- poj 3278 Catch That Cow 广搜
hdu 2717 Catch That Cow,题目链接 Time Limit: 5000/2000 MS (Java/Others) Memory Limit: 32768/32768 K (Jav ...
- POJ 3278 / hdu 2717 Catch That Cow (广搜)
POJ 3278 HDU 2717 广搜题,用一个数组标记就可以过,不标记的话会超内存. 另外,poj的数据要比hdu强一些,比如0 100,这种数据.不特判的话会RE.不过如果不特判,在poj上用C ...
- Catch That Cow——广搜
Catch That Cow Problem Description Farmer John has been informed of the location of a fugitive cow a ...
- poj 3728 Catch That Cow ([kuangbin带你飞]专题一 简单搜索)
题目大意:题目链接 就是给你N,K,每次有三种惭怍+1,-1,*2,,问多少次操作能到K 解题思路,搜索直接算,.,,,哎,啥时候这种垃圾搜索我能直接A 啊,太菜了 #include<cstdi ...
- POJ 3278 Catch That Cow
Catch That Cow Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 30924 Accepted: 9536 D ...
- BFS POJ 3278 Catch That Cow
题目传送门 1 /* 2 BFS简单题:考虑x-1,x+1,x*2三种情况,bfs队列练练手 3 */ 4 #include <cstdio> 5 #include <iostrea ...
- poj 3278 Catch That Cow(广搜)
Catch That Cow Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 45087 Accepted: 14116 ...
- POJ - 3278 Catch That Cow 简单搜索
Farmer John has been informed of the location of a fugitive cow and wants to catch her immediately. ...
- POJ 3278 Catch That Cow BFS
Catch That Cow Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 32071 Accepted: 9866 D ...
最新文章
- MessageBox只弹出一次
- Winform Datagridview 单元格html格式化支持富文本
- 怎么安装mysql8.0.20_Mysql 8.0.20安装教程
- 中国程序员最应该感谢的几家公司
- 正确的初始化,在 Java 编程中至关重要!
- 两个基于 PowerShell 的新后门盯上微软 Exchange 服务器
- 51Nod 1256 乘法逆元 Label:exgcd
- web安全的学习路线
- .Spark Streaming(上)--实时流计算Spark Streaming原理介
- python unpack 到数列_842. 将数组拆分成斐波那契数列(Python)
- 利用网线实现电脑间超大文件传输
- 女生宿舍,男生请勿进
- tp路由器桥接成功无法上网怎么办
- 【故障检测】基于 KPCA 的故障检测【T2 和 Q 统计指数的可视化】(Matlab代码实现)
- mtk使用android开关机动画,android MTK修改开关机动画
- java编写一个学生类和教师类_JAVA:1、编写一个学生类,类名为Student,包含如下成员:...
- JavaScript中Unicode编码和中文相互转换
- HM_SCC的调色板模式palette_mode编码流程整理
- 悖论在计算机中的应用,信息悖论
- Boundary Smoothing for NER
热门文章
- ipad4服务器未响应,ipad air常见问题及解决方法汇总
- 记录一次成都阿里一面的经历
- MATLAB画柱状图填充(多种)
- Python线性规划实践
- 【编程游戏】贺岁霓虹灯。(参观206楼xuyiazl的霓虹灯)
- idea 提示 TKK 更新TKK失败,请检查网络连接(有效解决)
- 大学计算机二级考试试题c,全国高校计算机等级二级C考试试题精选【选择题】2...
- 【面试题】谈谈你对vite的了解
- java 员工信息_JAVA控制台输入输出员工信息
- 虚拟内存,内存页面错误与页面错误增量如何处理。(整理)