hdoj 1026
来源:互联网 发布:php nginx 一键安装包 编辑:程序博客网 时间:2024/06/16 07:10
#include<iostream>#include<queue>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<Node, vector<Node>,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 <<endl; //}//vis[0][0] = 1;//flag = 1;//bfs();//if(flag == 0){//cout << "God please help our poor hero.\nFINISH\n";//}//else{//printPaht();//} //}return 0;}void ttt(){Node node[5];for(int i = 0; i < 3; i++ ){int x, y, s;scanf("%d%d%d",&x,&y,&s);node[i].x = x;node[i].y = y;node[i].step = s;pq.push(node[i]);}while(!pq.empty()){Node tmp = pq.top();pq.pop();cout << tmp.step <<endl;}}
阅读全文
0 0
- hdoj 1026
- hdoj 1026 搜索
- HDOJ 1026 BFS
- HDOJ
- hdoj
- hdoj
- HDOJ
- HDOJ 1026 Ignatius and the Princess I
- HDOJ 1026 Ignatius and the Princess I
- 【置换群】 HDOJ 1439 && POJ 1026 Cipher
- HDOJ 1026 Ignatius and the Princess I
- Hdoj 1026 Ignatius and the Princess I
- hdoj 1568 && hdoj 5344 && hdoj 5444
- HDOJ 1026 Ignatius and the Princess I 解题
- ACM HDOJ 1026(Ignatius and the Princess I)
- hdoj 1026 Ignatius and the Princess I 【BFS】
- hdoj 1026 Ignatius and the Princess I【bfs&&路径输出】
- HDOJ 1026 Ignatius and the Princess I 解题报告
- Spark SQL将数据写入Mysql表的一些坑
- 我的生产my.cnf
- java访问远程接口返回json数据接收
- maven的安装、路径配置、修改库文件路径和eclipse中的配置、创建maven工程。
- DICOM文件的读取显示和本地JPG格式的存储
- hdoj 1026
- ViewPager+Fragment组合的预加载和懒加载
- python nosetests
- 我的快速安装MySQL手册
- MFC中CMFCButton类改变颜色的使用
- kubernetes(k8s)以及涉及组件简单介绍
- Jvm 标记-清除法,复制算法,分代收集算法
- FFMPEG视音频编解码零基础学习方法
- HDU 2093 考试排名