hdu 149 胜利大逃亡(续)
来源:互联网 发布:it have 还是it has 编辑:程序博客网 时间:2024/05/18 14:15
http://acm.hdu.edu.cn/showproblem.php?pid=1429
第一次接触位运算,被坑了好久,一直不知道怎么标记,代码有点乱
#include<stdio.h>#include<queue>#include<string.h>using namespace std;int n,m,t;char map[20][20];int mov[4][2] = {1,0,0,1,-1,0,0,-1};struct node{int x,y,step;int letter;};bool book[20][20][1026];int bfs(int sx,int sy){memset(book,0,sizeof(book));queue<node>q;node p1,p2;p1.x = sx;p1.y = sy;p1.step = 0;p1.letter = 0;q.push(p1);while(!q.empty()){p1 = q.front();q.pop();int next_x,next_y;for(int i = 0;i<4;i++){p2 = p1;next_x = p1.x+mov[i][0];next_y = p1.y+mov[i][1];if(p1.step+1>=t)break;if(next_x<0 || next_y<0 || next_x>n-1 || next_y>m-1)continue;if(map[next_x][next_y]=='^')return p1.step+1;if(map[next_x][next_y]<='z' && map[next_x][next_y]>='a'){if(book[next_x][next_y][p1.letter | 1<<(map[next_x][next_y]-'a')] == true)continue;p2.letter = (p1.letter | 1<<(map[next_x][next_y]-'a'));}if(map[next_x][next_y]<='Z' && map[next_x][next_y]>='A'){if((p1.letter & 1<<(map[next_x][next_y]-'A'))==0)continue;}if(book[next_x][next_y][p1.letter] == false && map[next_x][next_y]!='*'){p2.step = p1.step+1;p2.x = next_x;p2.y = next_y;book[next_x][next_y][p1.letter] = true;q.push(p2);}}}return -1;}int main(){int sx,sy;while(scanf("%d%d%d",&n,&m,&t)!=EOF){getchar();for(int i = 0;i<n;i++){for(int j = 0;j<m;j++){scanf("%c",&map[i][j]);if(map[i][j]=='@')sx = i,sy = j;}getchar();}printf("%d\n",bfs(sx,sy));}return 0;}
0 0
- hdu 149 胜利大逃亡(续)
- hdu 胜利大逃亡
- HDU 1429 胜利大逃亡(续)
- hdu 1429胜利大逃亡(续)
- hdu 1429 胜利大逃亡(续)
- HDU 1429 胜利大逃亡(续)
- hdu 1429 胜利大逃亡(续)
- hdu 1429 胜利大逃亡(续)
- HDU 1429 胜利大逃亡(续)
- hdu 1429胜利大逃亡(续)
- HDU 1429 胜利大逃亡(续)
- hdu 1429 胜利大逃亡(续)
- hdu-1429 胜利大逃亡(续)
- HDU 1429 胜利大逃亡(续)
- Hdu 1429 胜利大逃亡(续)
- hdu 1429 胜利大逃亡(续)
- HDU--1429 胜利大逃亡(续)
- 1429 胜利大逃亡( 续 ) hdu
- ORACLE SQL性能优化二
- CSS3制作各种形状图像
- 找个大牛拿shell,网站权限,数据,重酬
- C# 多态性
- 协议森林08 不放弃 (TCP协议与流通信)
- hdu 149 胜利大逃亡(续)
- Webhook 实践 —— 自动部署
- 第一天开通博客
- hdu-5571 tree
- ORACLE SQL性能优化一
- Linux操作系统多线程同步Mutex详细介绍
- RecyclerView+Checkbox乱序问题
- Caffe训练过程:test_iter test_interval等概念
- ztree简单的使用