UVA 1600】的更多相关文章

UVA 1600 Patrol Robot   Time Limit:3000MS     Memory Limit:0KB     64bit IO Format:%lld & %llu   Description A robot has to patrol around a rectangular area which is in a form of mxn grid (m rows and n columns). The rows are labeled from 1 to m. The…
传送门: https://uva.onlinejudge.org/external/16/1600.pdf 多状态广搜 网上题解: 给vis数组再加一维状态,表示当前还剩下的能够穿越的墙的次数,每次碰到墙,当前的k减去1,碰到0,当前的k变成最初的k. vis[x][y][z]  x, y代表坐标  z表示k  当为真时说明该点剩余穿墙次数为k的状态已出现过 #include <bits/stdc++.h> using namespace std; typedef struct Node{ i…
Description A robot has to patrol around a rectangular area which is in a form of mxn grid (m rows and n columns). The rows are labeled from 1 to m. The columns are labeled from 1 to n. A cell (i, j) denotes the cell in row i and column j in the grid…
描述 A robot has to patrol around a rectangular area which is in a form of mxn grid (m rows and n columns). The rows are labeled from 1 to m. The columns are labeled from 1 to n. A cell (i, j) denotes the cell in row i and column j in the grid. At each…
带状态的bfs 用一个数(ks)来表示状态-当前连续穿越的障碍数: step表示当前走过的步数: visit数组也加一个状态: #include <iostream> #include <cstring> #include <cstdio> #include <queue> using namespace std; ; struct node { int x,y; int step; int ks; void init (int nx,int ny,int…
迷宫求最短路的话一般用bfs都可以解决,但是这个加了个状态,那么就增加一个维度,用来判断k的值.比较简单的三维bfs.写搜索题的话一定要注意细节.这个题花了好长的时间.因为k的原因,一开始用了k的原因,dfs好想一些,因为可以回溯,k的值搜完一个方向,然后回溯.那样就很简单.而且数据是20*20. 但是最后dfs还是T了. AC的bfs #include <iostream> #include <cstring> #include <string> #include &…
A robot has to patrol around a rectangular area which is in a form of m x n grid (m rows and ncolumns). The rows are labeled from 1 to m. The columns are labeled from 1 to n. A cell (i, j)denotes the cell in row i and column j in the grid. At each st…
这道题运用的知识点是求最短路的算法.一种方法是利用BFS来求最短路. 需要注意的是,我们要用一个三维数组来表示此状态是否访问过,而不是三维数组.因为相同的坐标可以通过不同的穿墙方式到达. #include <bits/stdc++.h> using namespace std; struct Node{ int r; int c; int g; int cnt; Node(int r,int c,int g,int cnt):r(r),c(c),g(g),cnt(cnt){} }; ][][]…
非常适合A*的一道题. 比普通的迷宫问题加一个信息k表示当前穿过的障碍物的数量. #include<cstdio> #include<cstring> #include<queue> using namespace std; ; int m,n,k; int C[MAX][MAX][MAX]; int G[MAX][MAX]; int tarx,tary; struct node { int g,h; int x,y;//对于本题 x+y 越大距离终点越近 int k;…
题意: 给定一个n*m的图, 有一个机器人需要从左上角(1,1)到右下角(n,m), 网格中一些格子是空地, 一些格子是障碍, 机器人每次能走4个方向, 但不能连续穿越k(0<= k <= 20)个障碍物, 求最短路径, 如无法到达输出 -1. 分析:   对于空地, 建一个vis数组记录走过的空地, 然后每次碰到没vis过的空地都把队伍K更新为最大值, vis这块地. 对于墙的情况, 我们可以建一个vis1数组去记录通过墙时候的k值, 如果之前有一个k值比现在要通过的大, 那么我们就不入队,…