博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
hdoj 1026
阅读量:4216 次
发布时间:2019-05-26

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

#include
#include
using namespace std;const int INF = 9999999;const int MAX = 105;struct Node{ int x, y; int step;};struct cmp{ bool operator () (const Node &a, const Node &b){ return a.step > b.step; }};struct Pre{ int x, y; int step;};Pre pre[MAX][MAX];int map[MAX][MAX];int vis[MAX][MAX];char in[MAX];int n, m;int flag;int dir[4][2] = {
{1,0},{-1,0},{0,1},{0,-1}}; priority_queue
,cmp> pq;//忘记声明变量了 void bfs() { Node start; start.x = 0; start.y = 0; start.step = 0; pq.push(start); while(!pq.empty()){ Node node = pq.top(); pq.pop(); if(node.x == n-1 && node.y == m-1){ flag = 1; //cout <<"Hello"; return; } vis[node.x][node.y] = 1; for(int i = 0; i < 4; i++ ){ int nx = node.x + dir[i][0]; int ny = node.y + dir[i][1]; if(nx < 0 || nx >= n || ny < 0 || ny >= m || vis[nx][ny] || map[nx][ny] == -1) continue; if(map[nx][ny] == 0){ pre[nx][ny].x = node.x; pre[nx][ny].y = node.y; pre[nx][ny].step = node.step; Node tmp; tmp.x = nx; tmp.y = ny; tmp.step = node.step + 1; pq.push(tmp); } else{ pre[nx][ny].x = node.x; pre[nx][ny].y = node.y; pre[nx][ny].step = node.step; Node tmp; tmp.x = nx; tmp.y = ny; tmp.step = node.step + map[nx][ny] + 1; pq.push(tmp); } } } }void printPaht() { } int main() {// while(scanf("%d%d",&n,&m) != EOF){// for(int i = 0; i < n; i++ ){// scanf("%s",in);// for(int j = 0; j < m; j++ ){// if(in[j] == '.'){// map[i][j] = 0;// }// else if(in[j] == 'X'){// map[i][j] = -1;// }// else{// map[i][j] = in[j]-'0';// }// // }// } // for(int i = 0; i < n; i++ ){// for(int j = 0; j < m; j++ ){// printf("%3d",map[i][j]);// }// cout <

转载地址:http://qlimi.baihongyu.com/

你可能感兴趣的文章
Yii2.0 数据库查询
查看>>
yii2 db 操作
查看>>
mongodb group 有条件的过滤组合个数。
查看>>
关于mongodb的 数组分组 array group
查看>>
MongoDB新的数据统计框架介绍
查看>>
mongodb 增加全文检索索引
查看>>
QC数据库表结构
查看>>
测试工具厂商的编程语言什么时候“退休”?
查看>>
资源监控工具 - Hyperic HQ
查看>>
LoadRunner中Concurrent与Simultaneous的区别
查看>>
SiteScope - Agentless监控
查看>>
为什么我们的自动化测试“要”这么难
查看>>
LoadRunner性能脚本开发实战训练
查看>>
测试之途,前途?钱途?图何?
查看>>
反病毒专家谈虚拟机技术 面临两大技术难题
查看>>
几种典型的反病毒技术:特征码技术、覆盖法技术等
查看>>
论文浅尝 | 通过共享表示和结构化预测进行事件和事件时序关系的联合抽取
查看>>
廖雪峰Python教程 学习笔记3 hello.py
查看>>
从内核看epoll的实现(基于5.9.9)
查看>>
python与正则表达式
查看>>