POJ 3626 BFS】的更多相关文章

思路:easy BFS //By SiriusRen #include <queue> #include <cstdio> #include <algorithm> using namespace std; queue<pair<int,int> >q; int x,y,jyx,jyy,n,xx[]={1,-1,0,0},yy[]={0,0,1,-1},vis[1555][1555]; bool map[1555][1555]; bool che…
题目链接: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…
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…
Red and Black Time Limit: 1000MS   Memory Limit: 30000K Total Submissions: 27891   Accepted: 15142 Description There is a rectangular room, covered with square tiles. Each tile is colored either red or black. A man is standing on a black tile. From a…
Language: Default Prime Path Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 11703   Accepted: 6640 Description The ministers of the cabinet were quite upset by the message from the Chief of Security stating that they would all have to c…
题意:给定两个四位素数作为终点和起点,每次可以改变起点数的某一位,且改变后的数仍然是素数,问是否可能变换成终点数字? 思路:bfs搜索,每次改变四位数中的某一位.素数打表方便判断新生成的数是否是素数. AC代码 #include<cstdio> #include<cstring> #include<queue> #include<cmath> using namespace std; const int maxn = 1e5 + 5; int vis[max…
立体bfs,共有六个方向: const int dx[] = {0,0,1,-1,0,0}; const int dy[] = {1,-1,0,0,0,0}; const int dz[] = {0,0,0,0,1,-1}; AC代码 #include<cstdio> #include<cstring> #include<queue> using namespace std; const int maxn = 32; char G[maxn][maxn][maxn];…
状态搜索,每种状态下面共有六种选择,将搜索到的状态保存即可. d[i][j]表示状态A杯中水i升,B杯中水j升,总状态数量不会超过A杯的容量 * B杯的容量. AC代码 #include<cstdio> #include<cstring> #include<algorithm> #include<queue> #include<string> #include<algorithm> #include<iostream> u…
bfs搜索过程中将路径保存下即可. AC代码 #include<cstdio> #include<cstring> #include<algorithm> #include<queue> using namespace std; const int maxn = 10; int G[maxn][maxn], d[maxn][maxn], pre[40]; const int dx[] = {1,-1,0,0}; const int dy[] = {0,0,-…
题意:给你一条蛇,要求一以最少的步数走到1,1 思路: 最开始一直没想到应该怎样保存状态,后来发现别人用二进制保存蛇的状态,即每两个节点之间的方向和头节点,二进制最多14位(感觉状态保存都能扯到二进制).然后就是bfs 问题: 1.最开始完全没想到状态压缩的问题 2.感觉现在做题太急,做题没有足够的思考,思路不清晰便开始写,导致在过程中经常崩盘. #include <iostream> #include <cstdio> #include <cmath> #includ…
题意: 求把S和所有的A连贯起来所用的线的最短长度... 这道题..不看discuss我能wa一辈子... 输入有坑... 然后,,,也没什么了...还有注意 一次bfs是可以求当前点到所有点最短距离的... #include <iostream> #include <cstdio> #include <cstring> #include <queue> #include <algorithm> #include <cmath> #d…
题意:可以把n边为n+1,n-1,n*2问从n到k的最少变化次数. 坑:标题写了.有点不会写bfs了... ac代码 #define _CRT_SECURE_NO_WARNINGS #include<cstring> #include<cctype> #include<cstdlib> #include<cmath> #include<cstdio> #include<string> #include<stack> #in…
DESCRIPTION:给你一个三维的迷宫.问你是否能从起点走到终点.如果能,输出最小步数.对我来说难得就是我没有想到怎么把他给你的三维图转换成map.恩..好像解题报告上说.只要是这种的最短路都要用bfs.用dfs回很难.不太懂耶.>_<... 然后就是普通的bfs了.然后忘了三个输入全为0的时候结束程序.然后WA了一会..然后就没有然后了.233333333333 附代码: #include<stdio.h>#include<string.h>#include<…
T_T ++运算符和+1不一样.(i+1)%4 忘带小括号了.bfs函数是bool 型,忘记返回false时的情况了.噢....debug快哭了...... DESCRIPTION:求最少的步骤.使得棋盘上的棋子全黑或者全白.奇数次相当于1次.偶数次相当于不翻. bfs用来求解最优问题.主要用来求距离初始状态路径最短的路径.思想是暴力枚举+位运算.第一次做位运算的题目..醉醉的啦...... 附代码: #include<stdio.h>#include<string.h>#incl…
注意求最短路的时候用Bfs. #include<iostream> #include<stdio.h> using namespace std; int w,h,ex,ey,sx,sy; int map[100][100],can[100][100]; struct vid{ int x,y,step; }queue[5000]; int zan[4][2]={{-1,0},{0,1},{1,0},{0,-1}}; int dirl[4][2]={0,-1,-1,0,0,1,1,0…
Eight Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 29935   Accepted: 13029   Special Judge Description The 15-puzzle has been around for over 100 years; even if you don't know it by that name, you've seen it. It is constructed with 15…
Flip Game Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 44450   Accepted: 19085 Description Flip game is played on a rectangular 4x4 field with two-sided pieces placed on each of its 16 squares. One side of each piece is white and the…
迷宫问题 Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 20665   Accepted: 12100 Description 定义一个二维数组: 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表示可以走的路,只能横着走或竖着走,不能斜着走…
Prime Path Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 14539   Accepted: 8196 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…
题目链接:http://poj.org/problem?id=1426 可能数据比较水,没有用到大整数.刚刚开始的时候,想从后往前加0或者1,发现有点难写,后来想到先放一个1,再1*10,1*10+1,这样也可以存遍历这种只有0和1的数,但是发现STL写队列会T,后来队列自己写,就A了. #include <stdio.h> ]; int main() { int n; while(scanf("%d",&n),n) { ; ; Q[rear++] = ; ) {…
Borg Maze Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 12032   Accepted: 3932 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 desc…
Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 9821   Accepted: 3283 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…
Pots Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 17456   Accepted: 7407   Special Judge Description You are given two pots, having the volume of A and B liters respectively. The following operations can be performed: FILL(i)        f…
题意:给你一个迷宫. 先输出当左转优先的时候走的路程长度,再输出当右转优先时走的路程长度,最后输出从起点到终点的最短路程长度. 嗯嗯 奴哥活跃气氛的题.随便写了写.. 此题 知道了思路以后就是水题了.... 再随便缩缩行也就不到40行 (网上的题解好多200+的..) 发现pair是个很坑的角儿.我一不小心就写挂了,重点是本机测试所有数据的输出结果都对.查不出来哪儿错的,,找了5min才找出来. 把 pair < int,int> *p=&q.front();然后就p->firs…