POJ 2457 BFS】的更多相关文章

题意: 说人话: 从A到B连边 找从1到k的最短路 并输出路径(随便一条即可 ) 如果不能到达 输出-1 思路: 搜 //By SiriusRen #include <queue> #include <cstdio> #include <cstring> #include <algorithm> using namespace std; #define N 100500 int n,k,xx,yy,first[N],next[N],w[N],v[N],tot…
题目链接:http://poj.org/problem?id=3249 思路:dp[i]表示到点i的最大收益,初始化为-inf,然后从入度为0点开始bfs就可以了,一开始一直TLE,然后优化了好久才4000ms险过. 之后有写了个dfs记忆化搜索,果然快多了. bfs AC code: #include<iostream> #include<cstdio> #include<cstring> #include<algorithm> #include<q…
http://poj.org/problem?id=2935 Basic Wall Maze Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 3220   Accepted: 1457   Special Judge Description In this problem you have to solve a very simple maze consisting of: a 6 by 6 grid of unit sq…
对于3维的,可以用结构体来储存,详细见下列代码. 样例可以过,不过能不能ac还不知道,疑似poj炸了, #include<iostream> #include<cstdio> #include<cstring> #include<queue> using namespace std; const int INF = 0x3f3f3f3f; int dx[] = {1, -1, 0, 0, 0, 0}; int dy[] = {0, 0, -1, 1, 0,…
Q - 迷宫问题 POJ - 3984 定义一个二维数组: int maze[5][5] = { 0, 1, 0, 0, 0, 0, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 0, 0, 0, 0, 1, 0, }; 它表示一个迷宫,其中的1表示墙壁,0表示可以走的路,只能横着走或竖着走,不能斜着走,要求编程序找出从左上角到右下角的最短路线. Input 一个5 × 5的二维数组,表示一个迷宫.数据保证有唯一解. Output 左上角到右下角的最短路径,格式如…
一道三维的BFS Dungeon Master Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 24003 Accepted: 9332 Description You are trapped in a 3D dungeon and need to find the quickest way out! The dungeon is composed of unit cubes which may or may not be f…
第一反应是BFS,比较直观,但是输出路径写的不是很熟练,此外,习惯不好,“==”写成了“=”,所以常量一定放前面! #include <cstdio> #include <queue> #include <cstring> using namespace std; int N, K; typedef struct node { int in, out; int pos; }Link; ; bool vis[maxn]; Link A[maxn]; int pre[max…
Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 9718   Accepted: 3263 Description The Borg is an immensely powerful race of enhanced humanoids from the delta quadrant of the galaxy. The Borg collective is the term used to describe the gr…
题目链接:http://poj.org/problem?id=3635 思路:本题主要运用的还是贪心思想,由于要求st->ed的最小花费,那么每经过一个城市,能不加油就尽量不加油,用dp[i][j]表示在顶点i,剩余燃料为j是的最小花费,于是每走到一个城市,可以选择不加油,也可以选择加1,2,3...,个单位的油,然后用优先队列来保存每个状态,如果有更小的花费,就入队列,这样直到第一次到达终点,此时花费就是最小的了. http://paste.ubuntu.com/5931435/…
Prime Path Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 15325   Accepted: 8634 Description The ministers of the cabinet were quite upset by the message from the Chief of Security stating that they would all have to change the four-dig…