POJ 3278
来源:互联网 发布:mysql是大型数据库吗 编辑:程序博客网 时间:2024/04/30 15:52
给出a和b点的横坐标,求到a,b的最小行动次数,其中每次行动只能是下面两种情况之一:
一,向左或向右移动一步,即横坐标加1或者减1
一,向左或向右移动一步,即横坐标加1或者减1
二,横坐标变成原来的两倍
//比较经典的一道广搜//走到的每一点,搜索它所能到达的点(点的范围是0到100000)#include <stdio.h>#include <stdlib.h>#include <string.h>#define MAX 200010struct node{ int number; int step;};struct node queue[MAX];int head;int tail;int book[MAX];int check(int number){ if(number<0||number>100000||book[number]) return 0; return 1;}int main(){ int n,m; while(scanf("%d%d",&n,&m)!=EOF){ memset(book,0,sizeof(book)); head=0; tail=0; queue[tail].number=n; queue[tail].step=0; book[n]=1; tail++; while(head<tail){ int num; num=queue[head].number; if(num==m){ printf("%d\n",queue[head].step); break; } if(check(num-1)){ queue[tail].number=num-1; queue[tail].step=queue[head].step+1; book[num-1]=1; tail++; } if(check(num+1)){ queue[tail].number=num+1; queue[tail].step=queue[head].step+1; book[num+1]=1; tail++; } if(check(num*2)){ queue[tail].number=num*2; queue[tail].step=queue[head].step+1; book[num*2]=1; tail++; } head++; } } return 0;}
1 0
- POJ 3278
- POJ 3278
- POJ 3278
- POJ 3278
- poj 3278
- poj 3278
- POJ 3278
- poj 3278
- POJ 3278
- poj 3278
- poj 3278
- poj 3278
- poj-3278
- poj--3278
- poj-3278
- poj 3278
- poj 3278
- poj 3278
- Problem D Parentheses
- Hibernate5配置异常Error executing DDL via JDBC Statement
- POJ 2395
- Codevs 1079 回家 最短路 spfa || dijkstra
- 第2.2章 WEB系统最佳实践Web.xml配置
- POJ 3278
- 【洛谷 1508】 Likecloud-吃、吃、吃
- Java——第三章(流程控制语句)项目案例
- Linux下查看SSD4K对齐EXT4分区开启Trim及验证的方法
- iOS 开发者必须知道的新特性
- 【七】最优间隔分类器问题
- 存储过程-第三课(函数)
- 【record】10.17..10.23
- 05 JS面向对象