hdu2425
来源:互联网 发布:全球拍软件多少钱 编辑:程序博客网 时间:2024/05/05 04:03
/*
分析:
简单广搜。
坑啊~,每组后面不用输出那个空行的。。。
接近半个月没怎么刷题了,惭愧呀~~~
2012-08-16 12:03
*/
分析:
简单广搜。
坑啊~,每组后面不用输出那个空行的。。。
接近半个月没怎么刷题了,惭愧呀~~~
2012-08-16 12:03
*/
#include"stdio.h"#include"string.h"#include"queue"using namespace std;int r,c;int base[4];int map[25][25];int flag[25][25];int x_s,y_s;int x_e,y_e;int dir[4][2]={1,0, -1,0, 0,1, 0,-1};struct node{int x,y;int step;friend bool operator<(node n1,node n2){return n2.step<n1.step;}};int judge(int x,int y){if(x<0 || x>=r || y<0 || y>=c)return 1;if(map[x][y]==-1)return 1;if(flag[x][y])return 1;return 0;}int BFS(){priority_queue<node>q;node now,next;int i;memset(flag,0,sizeof(flag));now.x=x_s;now.y=y_s;now.step=0;flag[now.x][now.y]=1;q.push(now);while(!q.empty()){now=q.top();q.pop();if(now.x==x_e && now.y==y_e)return now.step;for(i=0;i<4;i++){next.x=now.x+dir[i][0];next.y=now.y+dir[i][1];if(judge(next.x,next.y))continue;next.step=now.step+base[map[next.x][next.y]];flag[next.x][next.y]=1;q.push(next);}}return -1;}int main(){int Case=1;int i,l;char str[25];while(scanf("%d%d",&r,&c)!=-1){scanf("%d%d%d",&base[1],&base[2],&base[3]);for(i=0;i<r;i++){scanf("%s",str);for(l=0;str[l];l++){if(str[l]=='#')map[i][l]=1;else if(str[l]=='.')map[i][l]=2;else if(str[l]=='T')map[i][l]=3;else if(str[l]=='@')map[i][l]=-1;}}scanf("%d%d%d%d",&x_s,&y_s,&x_e,&y_e);printf("Case %d: %d\n",Case++,BFS());}return 0;}
- hdu2425
- hdu2425
- hdu2425解题报告
- hdu2425——Hiking Trip
- HDU2425:Hiking Trip(BFS+优先队列)
- HDU2425:Hiking Trip(BFS+优先队列)
- HDU2425 Hiking Trip(bfs+优先队列)
- 关于ListView的适配器中的getView方法调用多少次的现象探究,很诡异的!!!!
- IPV6服务器地址列表
- C++容易的泛型
- 在ubuntu部署hadoop之单机模式与伪分布式模式部署
- Network - closesocket() , shutdwonsocket()
- hdu2425
- 黑马程序员_交通灯系统
- 三种Windows中的定时或计时方法
- Android+Python[new version]
- 页面刷新时定位到原来的位置 C# 刷新
- 时间的函数,sleep,clock,gettickcount,....
- Logo! 24C 输出接线
- HDOJ4362-决策单调的DP
- 图像处理中的卷积运算