codeforces 242C King's Path STL库
来源:互联网 发布:cms技术架构 编辑:程序博客网 时间:2024/06/04 20:55
题意:在一个几乎无限大的棋盘上,有一个起点和终点。有一些格子是不可走的,一个问一个王从起点走向终点所需要的最小步数。王可以向八个周围的格子走。
做法:最多才100W个点,BFS暴力。
#include<iostream>#include<map>#include<deque>#include<cstdio>#define LMT 1000005using namespace std;//bfs,最短路也可用BFS暴力的//只有一百万个点,而且行动单一,直接BFSdeque<pair<int,int> > q;map<pair<int,int>,int> m;int x[]={1,-1,0,0,-1,-1,1,1},y[]={0,0,1,-1,1,-1,1,-1};int x0,y0,x1,y1,n;int main(void){ int xx,yy; scanf("%d%d%d%d%d",&y0,&x0,&y1,&x1,&n); while(n--) { int ri,ai,bi; scanf("%d%d%d",&ri,&ai,&bi); for(int j=ai;j<=bi;j++)m[make_pair(ri,j)]=-1; } m[make_pair(y0,x0)]=0; q.push_back(make_pair(y0,x0)); while(!q.empty()) { yy=q.front().first; xx=q.front().second; q.pop_front(); for(int i=0;i<8;i++) if(m[make_pair(yy+y[i],xx+x[i])]<0) { m[make_pair(yy+y[i],xx+x[i])]=m[make_pair(yy,xx)]+1; q.push_back(make_pair(yy+y[i],xx+x[i])); } } printf("%d\n",m[make_pair(y1,x1)]); return 0;}
- codeforces 242C King's Path STL库
- Codeforces 242C King‘s Path(BFS+STL)
- CodeForces 242C King's Path(bfs+stl)
- Codeforces-242C:King's Path(BFS+map)
- Codeforces-242C-King's Path(bfs)
- [CF 242C][BNUOJ 26638] King's Path [最短路]
- Codeforces 30D King's Problem? 模拟
- codeforces 30D King's Problem? 数学
- Codeforces Gym 100792K King's Rout
- Codeforces Gym 101142 K. King's Heir
- codeforces 3A - Shortest path of the king
- Codeforces 3A Shortest path of the king BFS
- codeforces 3A Shortest path of the king
- Codeforces 3A Shortest Path of the King
- Codeforces Round #3A. Shortest path of the king
- Codeforces Beta Round #3 A. Shortest path of the king
- Codeforces 3A. Shortest path of the king(贪心:暴力)
- CodeForces 3A - Shortest path of the king
- Matrix 矩阵,单位矩阵,Transposition,矩阵与矩阵相乘
- css menu sample
- 兼容ie,火狐的设为首页,加入收藏js代码
- 2011,夺回青春——《那些年,我们一起追的女孩》影评
- outlook附件保存位置
- codeforces 242C King's Path STL库
- linux下设定环境变量
- oracle job
- DSPLink中readwrite简析
- 基于用户投票的排名算法
- 标准标签库
- 通过javascript实现点击一个按钮触发发音的动作
- 一个基于组件的动态对象系统
- mysql调优