博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
裸BFS题若干
阅读量:4652 次
发布时间:2019-06-09

本文共 1001 字,大约阅读时间需要 3 分钟。

1poj 3278

#include
#include
#include
#include
#include
#include
using namespace std;#define N 100005#define M 155#define INF 0x3f3f3f3fstruct node{ int x, t;}st;int n, k, a, b, x, y, t, cnt, ans;bool v[N];void Bfs(int n){ ans = 0; queue
q; while(!q.empty()) q.pop(); memset(v, 0, sizeof(v)); st.x = n; st.t = 0; q.push(st); v[st.x] = 1; while(!q.empty()) { node head = q.front(); q.pop(); if(head.x == k) { ans = head.t; return; } for(int i = 0; i < 3; i++) { node next = head; if(i == 0) next.x = head.x + 1; else if(i == 1) next.x = head.x - 1; else next.x = head.x * 2; next.t = head.t + 1; if(next.x < 0 || next.x > 100000) continue; if(v[next.x] == 1 ) continue; // 一开始写成一行,if(v[next.x] == 1 || next.x < 0 || next.x > 100000) continue; 找了好久的bug,以后能分开的还是分开吧,不要省那一两行 q.push(next); v[next.x] = 1; } }}int main(){ while(cin>>n>>k){ Bfs(n); cout<
<

转载于:https://www.cnblogs.com/wmxl/p/11107303.html

你可能感兴趣的文章
SVN常用命令备注
查看>>
孩子教育
查看>>
解决Cacti监控图像断断续续问题
查看>>
结构体的传参理解成员的存储方式
查看>>
python 进程与线程(理论部分)
查看>>
什么是API
查看>>
[shiro学习笔记]第二节 shiro与web融合实现一个简单的授权认证
查看>>
强名称程序集(strong name assembly)——为程序集赋予强名称
查看>>
1028. List Sorting (25)
查看>>
BZOJ 1613: [Usaco2007 Jan]Running贝茜的晨练计划
查看>>
ubuntu 重启命令,ubuntu 重启网卡方法
查看>>
Linux的学习:
查看>>
JavaScript中的原型继承原理
查看>>
Python logger模块
查看>>
jquery控制css的display(控制元素的显示与隐藏)
查看>>
关于python做人工智能的一个网页(很牛逼)
查看>>
判断控件的CGRect是否重合,获取控件的最大XY值
查看>>
POJ-1128 Frame Stacking
查看>>
python第三十九课——面向对象(二)之初始化属性
查看>>
GET请求在Tomcat中的传递及URI传递
查看>>