Codeforces 242C King‘s Path(BFS+STL)
来源:互联网 发布:mac下面的图标太多 编辑:程序博客网 时间:2024/06/11 02:39
题目:给出一些可以走的点,这些点是一段一段的形式给出的,比如第5行的第1个格子到第4个格子是可以走的点。第二比较特别的是数据特别大,10^9的规模!果断是数组以及链表很难解决的东西呀!尤其是标记这部分!所以,map是必备的。用map不仅去标记是否允许走,还可以表示是否走过,并且存储可行点到起点的最短距离。
代码:
#include <cstdio>#include <map>#include <cstring>#include <vector>#include <queue>using namespace std;#define X first#define Y secondconst int N = 100010;int sx, sy, ex, ey;int n;int r[N], a[N], b[N];pair <int, int> p;map <pair<int, int>, int> mp;int ar1[] = { 0, 0, 1, -1, 1, -1, 1, -1 };int ar2[] = { 1, -1, 1, -1, 0, 0, -1, 1 };int main(){ while ( scanf("%d%d%d%d", &sx, &sy, &ex, &ey) != EOF ) { mp.clear(); p.first = sx, p.second = sy; scanf("%d", &n); for ( int i = 0; i < n; ++i ) { scanf("%d%d%d", &r[i], &a[i], &b[i]); for ( int j = a[i]; j <= b[i]; ++j ) { p.first = r[i], p.second = j; mp[p] = -1; } } queue < pair<int, int> > q; p.X = sx, p.Y = sy; mp[p] = 0; q.push(p); while ( !q.empty() ) { p = q.front(); q.pop(); for( int i = 0; i < 8; ++i ) { int x = p.X + ar1[i], y = p.Y + ar2[i]; pair <int, int> tmp; tmp.X = x, tmp.Y = y; if ( mp.count(tmp) && mp[tmp] == -1 ) { mp[tmp] = mp[p]+1; q.push(tmp); } } } p.X = ex, p.Y = ey; printf("%d\n", mp[p]); }}
- 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)
- codeforces 242C King's Path STL库
- [CF 242C][BNUOJ 26638] King's Path [最短路]
- Codeforces 3A-Shortest path of the king(BFS打印路径)
- Codeforces 3A Shortest path of the king BFS
- Codeforces 3A Shortest path of the king(BFS???NO!!)
- codeforces 3-A. Shortest path of the king(暴力)
- Codeforces 30D King's Problem? 模拟
- codeforces 30D King's Problem? 数学
- Codeforces Gym 100792K King's Rout
- Codeforces Gym 101142 K. King's Heir
- 【Codeforces】C. Ice Cave(bfs)
- Codeforces 590C Three States(bfs)
- CodeForces 540 C Ice Cave (BFS)
- codeforces 616C The Labyrinth(bfs)
- CentOS搭建xfce桌面+VNC教程
- hdu1839 二分+最短路
- hdu 1175 连连看
- 通过awk对日志文件每天统计并入库到MySQL的过程讲解
- 答题技巧
- Codeforces 242C King‘s Path(BFS+STL)
- 面试题300道
- 今天4-11
- struts2小笔记积累
- ADO.NET<数据库连接总汇>
- 第十一届中国国际软件合作洽谈会——ChinaSoft2013——2013年4月11日上午摘要
- setInterval() 方法使用
- android的启动出现loadlibrary failed with error 126:找不到指定模块。怎么解决。
- opencv-图像扫描,查表和处理时间选择(修改)