数格子,,简单bfs
来源:互联网 发布:windows tftp 服务器 编辑:程序博客网 时间:2024/05/07 13:13
第一篇博客要写一下bfs,数格子=_=
题目:
#include <iostream>#include <queue>#include <memory.h>using namespace std;int a[100];int n;struct node{ int w; int t;};int bfs(){ queue<node> Q; node s; s.w = s.t = 0; Q.push(s); while(!Q.empty()) { node now = Q.front(); Q.pop(); int i; for(i = 1; i <= a[now.w]; i++) { node newl; newl.w = now.w + i; newl.t = now.t + 1; Q.push(newl); if(newl.w == n-1) return newl.t; } } return -1;}int main(){ int t; cin>>t; while(t--) { int i, ans; cin>>n; for(i = 0; i < n; i++) cin>>a[i]; ans = bfs(); cout<<ans<<endl; } return 0;}
具体待解决的问题是循环体中始量的设定和终止,
以及就具体题而言的进队入队=_+.
0 0
- 数格子,,简单bfs
- 格子取数问题
- 【JZOJ 4787】 数格子
- [JZOJ4787] 数格子
- 【JZOJ4787】数格子
- 【NOIP模拟】数格子
- JZOJ 4787. 数格子
- 【JZOJ 4787】数格子
- 格子取数问题
- 格子取数2
- 格子取数3
- 格子取数问题
- Jzoj4787 数格子
- 403格子取数问题
- 【3011】数格子算面积
- 【NOIP提高组】数格子
- NYOJ 题目58 最少步数 (简单BFS)
- 【Codeforces Round 364 (Div 2)B】【简单讨论】Cells Not Under Attack 行列炮台覆盖不被攻击格子数
- 程序大牛的博客集锦
- Hadoop2.6.0中YARN底层状态机实现分析
- iOS 判断当前viewcontroller是push还是present的方式显示
- LightOJ--1049--One Way Roads(dfs)(好题)
- 第四课:ARM底层开发笔记之arm体系结构及异常处理
- 数格子,,简单bfs
- android socket长连接
- Set和List,HashSet与HasnMap,HashMap详解,HashSet详解
- C++ 继承
- php连接数库 和ca
- 等待多少秒后执行操作
- JS中判断null、undefined与NaN的方法
- 机器安装两个tomcat+ecplise同时配置两个tomcat
- 适配器模式