POJ3669 Meteor Shower 广度优先搜索
来源:互联网 发布:flash软件的利弊 编辑:程序博客网 时间:2024/05/20 22:40
这题就是个简单的广度优先搜索,注意的是,搜索过的地方要进行标记更新下,否则的话会超时。
#ifndef HEAD#include <stdio.h>#include <vector>#include <math.h>#include <string.h>#include <string>#include <iostream>#include <queue>#include <list>#include <algorithm>#include <stack>#include <map>using namespace std;#endif // !HEAD#ifndef QUADMEMSETinline void QuadMemSet(void* dst, int iSize, int value){iSize = iSize / 4;int* newDst = (int*)dst;#ifdef WIN32__asm{mov edi, dstmov ecx, iSizemov eax, valuerep stosd}#elsefor (int i = 0; i < iSize; i++){newDst[i] = value;}#endif}#endifint MS[305][305];char MSVISITed[301][301];bool g_bFind = false;int g_iMaxTime = 0;int MSSolve(){if (MS[0][0] > 1001)return 0;if (MS[0][0] == 0)return -1;queue<pair<int, int> > node;queue<int> timenode;node.push(pair<int, int>(0, 0));MSVISITed[0][0] = 1;timenode.push(0);int ANS = 100000000;while (node.size() != 0){pair<int, int> xy = node.front();node.pop();int t = timenode.front();timenode.pop();MSVISITed[xy.first][xy.second] = 1;if ( t + 1 < MS[xy.first + 1][xy.second] && t + 1 < ANS && MSVISITed[xy.first + 1][xy.second] == 0){if (MS[xy.first + 1][xy.second] > 1001){return t + 1;}MS[xy.first + 1][xy.second] = t + 1;node.push(pair<int, int>(xy.first + 1, xy.second));timenode.push(t + 1);}if (t + 1 < MS[xy.first][xy.second + 1] && t + 1 < ANS && MSVISITed[xy.first][xy.second + 1] == 0){if (MS[xy.first][xy.second + 1] > 1001){return t + 1;}MS[xy.first ][xy.second + 1] = t + 1;node.push(pair<int, int>(xy.first, xy.second + 1));timenode.push(t + 1);}if (xy.first > 0 && t + 1 < MS[xy.first - 1][xy.second] && t + 1 < ANS && MSVISITed[xy.first - 1][xy.second] == 0){if (MS[xy.first - 1][xy.second] > 1001){return t + 1;}MS[xy.first - 1][xy.second] = t + 1;node.push(pair<int, int>(xy.first - 1, xy.second));timenode.push(t + 1);}if (xy.second > 0 && t + 1 < MS[xy.first][xy.second - 1] && t + 1 < ANS && MSVISITed[xy.first][xy.second - 1] == 0){if (MS[xy.first][xy.second - 1] > 1001){return t + 1;}MS[xy.first][xy.second - 1] = t + 1;node.push(pair<int, int>(xy.first, xy.second - 1));timenode.push(t + 1);}}if (ANS >= 100000000){return -1;}return ANS;}int main(){#ifdef _DEBUGfreopen("d:\\in.txt", "r", stdin);#endifint n, m;while (scanf("%d\n", &n) != EOF){QuadMemSet(MS, sizeof(MS), 2000);QuadMemSet(map1, sizeof(map1), 500);memset(MSVISITed, 0, sizeof(MSVISITed));int x, y, t;for (int i = 0; i < n; i++){scanf("%d %d %d\n", &x, &y, &t);MS[x][y] = min(MS[x][y], t);MS[x + 1][y] = min(MS[x + 1][y], t);MS[x][y + 1] = min(MS[x][y + 1], t);if (x > 0)MS[x - 1][y] = min(MS[x - 1][y], t);if (y > 0)MS[x][y - 1] = min(MS[x][y - 1], t);}printf("%d\n", MSSolve());break;}return 0;}
0 0
- POJ3669 Meteor Shower 广度优先搜索
- 宽度优先搜索(BFS):POJ3669--Meteor Shower
- 【poj3669】Meteor Shower 搜索
- poj 3669 Meteor Shower(广度优先搜索)
- Meteor Shower (POJ 3669,广度优先搜索)
- POJ3669 Meteor Shower BFS
- poj3669 Meteor Shower BFS
- POJ3669 Meteor Shower(BFS)
- POJ3669 Meteor Shower 【BFS】
- POJ3669-Meteor Shower
- POJ3669 Meteor Shower
- POJ3669-Meteor Shower-BFS
- poj3669 Meteor Shower bfs
- Poj3669 meteor shower bfs
- poj3669-Meteor Shower
- POJ3669 Meteor Shower (BFS)
- POJ3669 Meteor Shower
- POJ3669 Meteor Shower(bfs)
- Beats起诉多家中国仿冒品企业:索赔数十亿美元
- cocos2d-x 3.1.1 在vs2012上新建工程
- CorePlot学习八---如何更新数据
- windows下手动配置ipv6地址
- Material Design
- POJ3669 Meteor Shower 广度优先搜索
- 联想ThinkPad 官网驱动下载 对应你的电脑的型号
- SQL T型结构的累加方式 over
- 1020. 月饼 (25)
- Windows Phone Style样式的四种使用
- 《老男孩》上映 “娱乐宝”投资电影进入回收期
- 文件数据如何实现定期自动备份
- Qt一步一步实现插件调用(附源码)、Qt一步一步实现插件通信(附源码)
- STARTUP.A51详解