hdu2717 Catch That Cow
http://acm.hdu.edu.cn/showproblem.php?pid=2717
//水搜。。。
1 #include<stdio.h> 2 #include<math.h> 3 #include<string.h> 4 #include<stdlib.h> 5 #include<iostream> 6 #include<queue> 7 using namespace std; 8 struct stu{ 9 int x; 10 int t; 11 }abc,q; 12 int n,k; 13 int vis[100005]; 14 void bfs() 15 { 16 queue<struct stu>p; 17 p.push(abc); 18 while(!p.empty()) 19 { 20 abc=p.front(); 21 p.pop(); 22 if(abc.x==k) 23 { 24 printf("%d\n",abc.t); 25 return ; 26 } 27 q.x=abc.x-1; 28 if(q.x>=0&&q.x<=100000&&!vis[q.x]) 29 { 30 q.t=abc.t+1; 31 vis[q.x]=1; 32 p.push(q); 33 } 34 q.x=abc.x+1; 35 if(q.x>=0&&q.x<=100000&&!vis[q.x]) 36 { 37 q.t=abc.t+1; 38 vis[q.x]=1; 39 p.push(q); 40 } 41 q.x=abc.x*2; 42 if(q.x>=0&&q.x<=100000&&!vis[q.x]) 43 { 44 q.t=abc.t+1; 45 vis[q.x]=1; 46 p.push(q); 47 } 48 } 49 } 50 51 int main() 52 { 53 //freopen("in.txt","r",stdin); 54 while(~scanf("%d%d",&n,&k)) 55 { 56 memset(vis,0,sizeof(vis)); 57 abc.x=n; 58 abc.t=0; 59 vis[n]=1; 60 bfs(); 61 } 62 return 0; 63 }
hdu2717 Catch That Cow相关推荐
- POJ3278 HDU2717 Catch That Cow【BFS】
Catch That Cow Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 100475 Accepted: 31438 ...
- HDU2717 Catch That Cow ( BFS )
Catch That Cow Time Limit:2000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u Desc ...
- HDU2717 Catch That Cow(bfs)
题意:农夫的牛跑了,给出农夫和牛在坐标轴上的位置n和k,农夫每次只能从点n移动到n-1.n+1或者n*2的位置.输出抓到牛所需要的最小移动次数. 思路:思路明显的bfs,每次搜索只按照这三种方式,标记 ...
- 【搜索入门专题1】hdu2717 H - Catch That Cow 【BFS】
Catch That Cow Problem Description Farmer John has been informed of the location of a fugitive cow a ...
- C - Catch That Cow POJ - 3278
C - Catch That Cow POJ - 3278 首先是大暴搜+最优化剪枝(当当前搜索情况不如已有答案优时,返回) #include<cstdio> #include<al ...
- POJ 3278 Catch That Cow
Catch That Cow Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 35043 Accepted: 10800 ...
- POJ 3278 Catch That Cow
Catch That Cow Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 30924 Accepted: 9536 D ...
- POJ 3278 Catch That Cow BFS
Catch That Cow Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 32071 Accepted: 9866 D ...
- POJ 3278 Catch That Cow(BFS)
题目网址:http://poj.org/problem?id=3278 题目: Catch That Cow Time Limit: 2000MS Memory Limit: 65536K Tot ...
最新文章
- python数据去噪声_Logreduce:用Python和机器学习去除日志噪音
- tomcat和nginx的使用
- 如何自学python基础-零基础小白该如何学习Python?
- 面向切面(AOP)之Spring接口方式 schema配置方式 aspectj注解方式
- IOS基础使用PCH文件全局定义宏常量
- java swing 实现下拉列表点击事件
- LeetCode输入字符串,倒序输出---C语言
- 到底有多二 (15 分)
- vb6 由于超出容量限制 不能创建新事务_Executors类创建四种常见线程池
- jdk1.8中文帮助文档
- visual assist x vs2019番茄助手
- IP地址作用与分类(A类 B类 C类 D类 E类)
- 关于SASL的介绍文档
- ITIL 系列bussiness 1
- 三年老Android经验面经,写给正在求职的安卓开发
- 倍福plc的型号_EL9186——plc倍福模块+EL9100型号EL9010
- NAS私有云存储 - 搭建Nextcloud私有云盘并公网远程访问
- STM32入门-学习STM32要掌握的内容
- 日期格式之间的互相转换
- “顾客至上,服务至上”??
热门文章
- Qt系列文章之二十五(使用QAudiolnput获取音频输入)
- oracle sap金蝶,SAP、金蝶、ORA、用友ERP系统的对比
- ie8浏览器html圆角问题,IE7,IE8浏览器CSS实现正圆角效果代码
- [分享]电脑故障应急处理宝典
- 7 大主题、9 位技术大咖。龙蜥大讲堂7月硬核直播预告抢先看,今天见~
- 【预测模型-ELM预测】基于原子搜索算法优化极限学习机预测matlab代码
- App安全测试-软件权限/安装与卸载安全性
- 高级计量经济学及stata应用 学习笔记② 短面板
- 关于苹果开发者账号申请付费流程
- 武汉理工大学自动化学院研究生07年就业情况(官方统计)