标签:nbsp color tor tom integer style rds nim empty
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 29856 Accepted Submission(s): 10515
1 /* 2 Name: HDU--1242--Rescue 3 Copyright: ?2017 日天大帝 4 Author: 日天大帝 5 Date: 22/04/17 19:18 6 Description: BFS,第一次搜索一遍过,留文纪念 7 */ 8 #include<iostream> 9 #include<queue> 10 #include<cstring> 11 using namespace std; 12 struct node{ 13 int x,y,steps; 14 node():steps(0){ 15 }; 16 bool operator<(const node &a)const { 17 return steps>a.steps; 18 } 19 }; 20 int n,m; 21 node s,e; 22 int dir[4][2] = {0,1,0,-1,1,0,-1,0}; 23 char map[205][205]; 24 void bfs(){ 25 priority_queue<node> q; 26 q.push(s); 27 map[s.x][s.y] = ‘#‘; 28 while(!q.empty()){ 29 node a,temp = q.top();q.pop(); 30 for(int i=0; i<4; ++i){ 31 a = temp; 32 a.x += dir[i][0]; 33 a.y += dir[i][1]; 34 if(a.x<0||a.y<0||a.x>=n||a.y>=m|| map[a.x][a.y] == ‘#‘)continue; 35 if(a.x == e.x&& a.y == e.y){ 36 cout<<a.steps+1<<endl;return ; 37 } 38 if(map[a.x][a.y] == ‘.‘)a.steps++; 39 else a.steps += 2; 40 map[a.x][a.y] = ‘#‘; 41 q.push(a); 42 } 43 } 44 cout<<"Poor ANGEL has to stay in the prison all his life."<<endl; 45 } 46 int main(){ 47 ios::sync_with_stdio(false); 48 49 while(cin>>n>>m){ 50 memset(map,0,sizeof(map)); 51 for(int i=0; i<n; ++i){ 52 cin>>map[i]; 53 for(int j=0; j<m; ++j){ 54 if(map[i][j] == ‘r‘){ 55 s.x = i;s.y = j; 56 } 57 if(map[i][j] == ‘a‘){ 58 e.x = i;e.y = j; 59 } 60 } 61 } 62 bfs(); 63 } 64 return 0; 65 }
标签:nbsp color tor tom integer style rds nim empty
原文地址:http://www.cnblogs.com/rtdd/p/6748904.html