POJ3278http://poj.org/problem?id=3278
#include<stdio.h>
#include<stdlib.h>
#include<math.h>
#include<string.h>
#include<queue>
#define max(a, b)(a > b ? a : b)
#define N 100010 using namespace std; struct node
{
int x, step;
}; int m, n;
bool vis[N]; int judge(int x)
{
if(x <= && x >= && !vis[x])
return ;
return -;
} int BFS(int x)
{
queue<node>Q;
node now, next;
now.x = x;
now.step = ;
vis[now.x] = true;
Q.push(now);
while(!Q.empty())
{
now = Q.front();
Q.pop();
if(now.x == n)
return now.step;
next.x = now.x + ;
if(judge(next.x) == )
{
vis[next.x] = true;
next.step = now.step + ;
Q.push(next);
}
next.x = now.x - ;
if(judge(next.x) == )
{
vis[next.x] = true;
next.step = now.step + ;
Q.push(next);
}
next.x = now.x * ;
if(judge(next.x) == )
{
vis[next.x] = true;
next.step = now.step + ;
Q.push(next);
}
}
return -;
}
int main()
{
while(scanf("%d%d", &m, &n)!= EOF)
{
memset(vis, false, sizeof(vis));
printf("%d\n", BFS(m));
}
return ;
}
POJ3278http://poj.org/problem?id=3278的更多相关文章
- http://poj.org/problem?id=3278(bfs)
Catch That Cow Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 76935 Accepted: 24323 ...
- poj 1651 http://poj.org/problem?id=1651
http://poj.org/problem?id=1651Multiplication Puzzle Time Limit: 1000MS Memory Limit: 65536K To ...
- poj-3056 http://poj.org/problem?id=3056
http://poj.org/problem?id=3056 The Bavarian Beer Party Time Limit: 6000MS Memory Limit: 65536K Tot ...
- poj 1679 http://poj.org/problem?id=1679
http://poj.org/problem?id=1679 The Unique MST Time Limit: 1000MS Memory Limit: 10000K Total Submis ...
- 最小生成树 10.1.5.253 1505 poj 1258 http://poj.org/problem?id=1258
#include <iostream>// poj 1258 10.1.5.253 1505 using namespace std; #define N 105 // 顶点的最大个数 ( ...
- poj 1915 http://poj.org/problem?id=1915
/**< */#include <stdio.h> #include <string.h> #include <stdlib.h> #include < ...
- Roadblocks http://poj.org/problem?id=3255
Description Bessie has moved to a small farm and sometimes enjoys returning to visit one of her best ...
- http://poj.org/problem?id=2253
floyd的应用求每条路径两点之间最大距离的最小值 #include <iostream> #include <cstdio> #include <algorithm&g ...
- 线段树 (区间更新,区间查询) poj http://poj.org/problem?id=3468
题目链接 #include<iostream> #include<cstdio> #include<cmath> #include<cstdlib> # ...
随机推荐
- Lunix中文乱码解决方案
sudo vi /var/lib/locales/supported.d/local#添加下面的中文字符集zh_CN.GBK GBKzh_CN.GB2312 GB2312zh_CN.GB18030 G ...
- mysqldump批量导出(多张表)表结构及表数据
Mysql 批量导出表结构(数据) 仅导出结构,不导出数据: 1.导出數據库為dbname的表结构 mysqldump -h主机地址 -u用户名 -p密码 -d dbname >db.s ...
- [LeetCode#249] Group Shifted Strings
Problem: Given a string, we can "shift" each of its letter to its successive letter, for e ...
- System.exit(0)
表示程序正常退出 System.exit(status) 当status非0时,表示程序为非正常退出. status=0, 关闭当前正在运行的虚拟机. 求质因数分解的程序如下: 两种算法: 一种是用S ...
- poj 1392 Ouroboros Snake
题目描述:咬尾蛇是古埃及神话中一种虚构的蛇.它经常把尾巴放在自己的嘴巴里,不停地吞噬自己.环数类似于咬尾蛇,它是2^n位的二进制数,具有如下性质:它能“生成”0-2^n-1之间的所有数.生成方法是:给 ...
- http请求返回响应码的意思
HTTP 状态响应码 意思详解/大全 HTTP状态码(HTTP Status Code)是用以表示网页服务器HTTP响应状态的3位数字代码.它由 RFC 2616 规范定义的,并得到RFC 2518. ...
- 【字符串处理】HDOJ-1020-Encoding
[题目链接:HDOJ-1020] 相邻字符,两两比较. #include<cstdio> #include<cstring> ; char sr[MAXN]; int main ...
- Kotlin 语言高级安卓开发入门
过去一年,使用 Kotlin 来为安卓开发的人越来越多.即使那些现在还没有使用这个语言的开发者,也会对这个语言的精髓产生共鸣,它给现在 Java 开发增加了简单并且强大的范式.Jake Wharton ...
- U1 - A 留在电脑里的字体
U1系列新篇章,实战派!说说常用的字体! U1系列新篇章,实战派!更多干货更多关于软件的使用等即将放出,大家敬请期待!!
- Creating SharePoint 2010 Event Receivers in Visual Studio 2010
转:http://msdn.microsoft.com/en-us/library/gg252010(v=office.14).aspx Summary: Learn how to create a ...