poj 3669 bfs
来源:互联网 发布:python proxyfix 编辑:程序博客网 时间:2024/05/19 04:54
#include <queue>#include <cstdio>#include <algorithm>#include <iostream>#include <cmath>#include <cstring>using namespace std;const int maxn = 305;const int inf = 0x3f3f3f3f;int mark[maxn][maxn];int dx[4] = {0, 0, 1, -1};int dy[4] = {1, -1, 0, 0};bool within(int x, int y){ return x >= 0 && y >= 0;}struct Node{ int x, y, t;};queue<Node> q;int main(){ int n; cin>>n; memset(mark, 0x3f, sizeof(mark)); for (int i = 0; i<n;i++){ int x, y, t; scanf("%d%d%d", &x, &y, &t); mark[x][y] = min(mark[x][y], t); for (int j=0;j<4;j++){ int tx = x + dx[j], ty = y + dy[j]; if (!within(tx, ty)){ continue; } mark[tx][ty] = min(mark[tx][ty], t); } } if (mark[0][0] == 0){ cout << -1 << endl; return 0; } q.push(Node({0,0,0})); while(q.size()){ int x = q.front().x; int y = q.front().y; int t = q.front().t; q.pop(); for (int k=0;k<4;k++){ int tx = dx[k] + x, ty = dy[k] + y; if (!within(tx,ty)){ continue; } if (mark[tx][ty] <= t + 1){ continue; } if (mark[tx][ty] == inf){ cout << t + 1 << endl; return 0; } mark[tx][ty] = 0; q.push(Node({tx, ty, t + 1})); } } cout << -1 << endl; return 0;}
阅读全文
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
- 剑指offer:(37)时间效率和空间效率的平衡 :两个链表的第一个公共结点
- Android事件分发机制以及滑动冲突处理
- JAVA:二进制与十进制转换
- What is a Servlet?
- 牛客网_华为机试_023_删除字符串中出现次数最少的字符
- poj 3669 bfs
- [编程题] 微信红包
- 从join on和where执行顺序认识T-SQL查询处理执行顺序
- hadoop 日志及历史服务器
- 类的动态分配内存与释放
- H264码流中SPS PPS详解
- 没事刷刷题之三 产生冠军 HDOJ 2094
- python学习笔记(五)
- 全文检索Lucene(四)---Compass框架