标签:des style blog http color java os io
http://acm.hdu.edu.cn/showproblem.php?pid=4308
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 2305 Accepted Submission(s): 822
#include <iostream> #include <stdio.h> #include <string.h> #include <stdlib.h> using namespace std; int n,m,V; char map[1001][1001]; int v[1001][1001]; struct node { int x,y,ans; }q[100001]; int jx[]={1,-1,0,0}; int jy[]={0,0,1,-1}; void bfs(int xx,int yy) { int e=0; int s=0; memset(v,0,sizeof(v)); struct node t,f; t.x=xx; t.y=yy; t.ans=0; v[t.x][t.y]=1; q[e++]=t; while(s<e) { t=q[s++]; if(map[t.x][t.y]==‘C‘) { printf("%d\n",t.ans); return ; } for(int i=0;i<4;i++) { f.x=t.x+jx[i]; f.y=t.y+jy[i]; if(f.x>=0&&f.x<n&&f.y>=0&&f.y<m&&map[f.x][f.y]!=‘#‘&&v[f.x][f.y]==0) { if(map[f.x][f.y]==‘*‘) { f.ans=t.ans+V; q[e++]=f; v[f.x][f.y]=1; } else if(map[f.x][f.y]==‘C‘) { f.ans=t.ans; q[e++]=f; v[f.x][f.y]=1; } else if(map[f.x][f.y]==‘P‘) { for(int j=0;j<n;j++) { for(int k=0;k<m;k++) { if(map[j][k]==‘P‘) { f.ans=t.ans; f.x=j; f.y=k; q[e++]=f; v[f.x][f.y]=1; } } } } } } } printf("Damn teoy!\n"); return ; } int main() { int xx,yy; while(scanf("%d%d%d",&n,&m,&V)!=EOF) { for(int i=0;i<n;i++) scanf("%*c%s",map[i]); int j; for(int i=0;i<n;i++) { for(j=0;j<m;j++) { if(map[i][j]==‘Y‘) { xx=i; yy=j; break; } } if(j!=m) break; } bfs(xx,yy); } return 0; }
Saving Princess claire_(hdu 4308 bfs模板题),布布扣,bubuko.com
Saving Princess claire_(hdu 4308 bfs模板题)
标签:des style blog http color java os io
原文地址:http://www.cnblogs.com/zhangmingcheng/p/3918201.html