POJ 3669 bfs
来源:互联网 发布:世界上的另一个你知乎 编辑:程序博客网 时间:2024/06/04 20:07
解题思路是看别人的,但是提交的时候WA了一次,看一下是数组初始化小了,我初始到了300*300,但是题中的意思是可以到301的,因此又重新初始到了302*302。
解题思路:http://www.cnblogs.com/7hat/p/3595630.html
代码如下:
//<cpp>#include<iostream>#include<cstdio>#include<queue>#include<algorithm>#define INF 10000000using namespace std;typedef pair<int,int> P;int x[50005],y[50005],t[50005];int maze[305][305];int d[305][305];int dx[]={1,0,-1,0};int dy[]={0,1,0,-1};int M;int bfs(){ if(maze[0][0]==0) return -1; queue<P> que; que.push(P(0,0)); d[0][0]=0; while(!que.empty()) { P p =que.front(); que.pop(); int x=p.first,y=p.second; if(maze[x][y]==INF) return d[x][y]; for(int i=0;i<4;i++) { int nx=x+dx[i],ny=y+dy[i]; if(nx>=0&&ny>=0&&d[nx][ny]==INF&&d[x][y]+1<maze[nx][ny]) { que.push(P(nx,ny)); d[nx][ny]=d[x][y]+1; } } } return -1;}void solve(){ for(int i=0;i<=302;i++) for(int j=0;j<=302;j++) { maze[i][j]=INF; d[i][j]=INF; } for(int i=0;i<M;i++) { maze[x[i]][y[i]]=min(maze[x[i]][y[i]],t[i]); for(int j=0;j<4;j++) { int nx=x[i]+dx[j]; int ny=y[i]+dy[j]; if(nx>=0&&ny>=0) maze[nx][ny]=min(maze[nx][ny],t[i]); } } int ans=bfs(); printf("%d\n",ans);}int main(){ scanf("%d",&M); for(int i=0;i<M;i++) scanf("%d%d%d",&x[i],&y[i],&t[i]); solve();}
0 0
- POJ 3669 BFS
- poj 3669 (BFS)
- poj 3669 bfs
- poj 3669 bfs
- poj 3669 BFS
- poj 3669 bfs
- POJ 3669 -- BFS
- poj 3669 bfs+预处理
- 集训 Poj 3669 BFS
- POJ 3669 简单BFS
- POJ 3669 bfs
- poj 3669 bfs
- poj 3669 Meteor Shower (bfs)
- POJ 3669-Meteor Shower(BFS)
- POJ 3669 Meteor Shower(BFS)
- POJ 3669 Meteor Shower BFS
- POJ 3669 Meteor Shower(BFS)
- POJ-3669 Meteor Shower BFS
- 常用linux系统命令
- 让你的apk减减肥
- 一起学安全测试——Burp Suite Proxy与浏览器设置
- android中线程和进程
- 学习笔记
- POJ 3669 bfs
- 前端知道分享,移动端布局
- mssql用cmd命令执行*.sql文件
- jsp和servlet的区别
- ASP.NET MVC上传文件的方法
- 源码解析Android中View的measure量算过程
- 线程方法和对象
- 产生死锁的原因和必要条件+解决死锁的基本方法
- 计算机视觉领域的顶级国际会议和期刊列表