数据结构——UVA 1600 机器人巡逻】的更多相关文章

描述 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都可以解决,但是这个加了个状态,那么就增加一个维度,用来判断k的值.比较简单的三维bfs.写搜索题的话一定要注意细节.这个题花了好长的时间.因为k的原因,一开始用了k的原因,dfs好想一些,因为可以回溯,k的值搜完一个方向,然后回溯.那样就很简单.而且数据是20*20. 但是最后dfs还是T了. AC的bfs #include <iostream> #include <cstring> #include <string> #include &…
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…
非常适合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;…
题意:从(1,1)走到(m,n),最多能连续穿越k个障碍,求最短路. 分析:obstacle队列记录当前点所穿越的障碍数,如果小于k可继续穿越障碍,否则不能,bfs即可. #pragma comment(linker, "/STACK:102400000, 102400000") #include<cstdio> #include<cstring> #include<cstdlib> #include<cctype> #include&l…
传送门: 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…
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…
https://vjudge.net/problem/UVA-12549 题意: 在一个Y行X列的网格里有空地(.),重要位置(*)和障碍物(#),用最少的机器人看守所有重要位置,每个机器人要放在一个格子里,面朝上下左右4个方向之一.机器人会发出激光,一直射到障碍物为止,沿途都是看守范围. 思路: 把每个坐标的x和y值连成一条边,分别作为二分图的两边,用最少的点去覆盖所有的边,也就是二分图的最大匹配.由于有障碍物的存在,在建图的时候需要拆分点. #include<iostream> #incl…
题意: 给定一个n*m的图, 有一个机器人需要从左上角(1,1)到右下角(n,m), 网格中一些格子是空地, 一些格子是障碍, 机器人每次能走4个方向, 但不能连续穿越k(0<= k <= 20)个障碍物, 求最短路径, 如无法到达输出 -1. 分析:   对于空地, 建一个vis数组记录走过的空地, 然后每次碰到没vis过的空地都把队伍K更新为最大值, vis这块地. 对于墙的情况, 我们可以建一个vis1数组去记录通过墙时候的k值, 如果之前有一个k值比现在要通过的大, 那么我们就不入队,…
题意 : 机器人要从一个m * n 网格的左上角(1,1) 走到右下角(m, n).网格中的一些格子是空地(用0表示),其他格子是障碍(用1表示).机器人每次可以往4个方向走一格,但不能连续地穿越k(0≤k≤20)个障碍,求最短路长度.起点和终点保证是空地. 分析 : 很明显的BFS最短路,但是这里有坑呀!如果只是单纯使用二维数组去标记是否已经访问过改点是错误的做法,走到该点的机器人因为有穿越障碍物的步数限制,所以可能有些 略绕但是行得通的路 就会被二维数组这种标记方式把路给封死,比如下面这个例…
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…
带状态的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来求最短路. 需要注意的是,我们要用一个三维数组来表示此状态是否访问过,而不是三维数组.因为相同的坐标可以通过不同的穿墙方式到达. #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){} }; ][][]…
题意:给出一个n*m的矩阵,1代表墙,0代表空地,不能连续k次穿过墙,求从起点到达终点的最短路的长度 给vis数组再加一维状态,表示当前还剩下的能够穿越的墙的次数,每次碰到墙,当前的k减去1,碰到0,当前的k变成最初的k 学习的这一篇 http://www.cnblogs.com/bingolibing/p/3873822.html #include<iostream> #include<cstdio> #include<cstring> #include <cm…
机器人要从一个m*n(m和n的范围都在1到20的闭区间内)的网格的左上角(1,1)走到右下角(m,n).网格中的一些格子是空地,用0表示,其它格子是障碍,用1表示.机器人每次可以往四个方向走一格,但不能连续地穿越k( [0,20] )个障碍,求最短路长度.起点和终点保证是空地. 思路:用bfs搜索即可,由于不能连续地穿越k个障碍,所以在原本的vis2维数组上面再添加1维,变成3维数组,表示穿越的墙的层数(障碍). #include<cstdio> #include<cstring>…
巡逻机器人 题目链接:http://acm.hust.edu.cn/vjudge/contest/view.action?cid=83498#problem/F 题目大意: 机器人在一个矩形区域巡逻,是一网格(m行和n列).从左上角(1,1)到右下角(m,n).网络格 中的一些格子是空地(用0表示),其他格子是障碍(用1表示).机器人每次有4个方向走,但不能 连续穿越k障碍,求最短长度. 分析: 用bfs进行搜索,不过当遇到障碍的时候记录下,当遇到的障碍超过k时,返回到上一步. #include…
巡逻机器人问题(F - BFS,推荐) 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 an…
I Can Guess the Data Structure! There is a bag-like data structure, supporting two operations: 1 x Throw an element x into the bag. 2 Take out an element from the bag. Given a sequence of operations with return values, you're going to guess the data…
  Robot Instructions  You have a robot standing on the origin of x axis. The robot will be given some instructions. Your task is to predict its position after executing all the instructions. LEFT: move one unit left (decrease p by 1, where p is the p…
用(x,s)表示一个状态,x表示机器人的位置,s表示其他位置有没有物体.用个fa数组和act数组记录和打印路径,转移的时候判断一下是不是机器人在动. #include<bits/stdc++.h> using namespace std; ; ; +; // 2^15*15 int head[maxn],to[maxe],nxt[maxe]; int ecnt; void addEdge(int u,int v) { to[ecnt] = v; nxt[ecnt] = head[u]; hea…
P.S.我完全一个字一个字敲出来的血泪史啊~~所以,没有附代码,也是可以理解的啦.OvO 题意:给一个长度为N(N≤200000)的序列,要删除一个连续子序列,使得剩下的序列中有一个长度最大的连续递增子序列,输出其长度. 解法:(参考自紫书)1.X 暴力枚举删除的区间 [l,r],O(n^2),再数需要O(n).总共O(n^3). 2.X 前者+O(n)预处理 f[i] 和 g[i] 表示前缀和后缀的长度最大的连续递增子序列长度.总共O(n^2). 3.√ 前者O(n)预处理+ 只枚举 r(部分…
一开始按照标准bfs来写  标记为二维数组 后来按照三维数组写过了    ps大部分bfs都不会是二维数组搞定!!! 其中有一个bug弄了半个小时... 一开始我是先判断!vis[x][y][v.c] 再判断方块是否为1  是的话v.c++:否的话归零 但是 这并不科学   到另外一个方块的时候    如果数组下标内容和结构体有关的话  应该先改变状态再判断   就如同肯定是先在u的基础上改变dx dy  再判断v.x v.y  一个道理  不然会超时!因为头不对尾 #include<bits/…
/* * UVA_630.cpp * * Created on: 2013年11月4日 * Author: Administrator */ #include <iostream> #include <cstdio> #include <map> #include <string> #include <algorithm> using namespace std; int main(){ int t; scanf("%d",&…
题目 题目     分析 bfs可以搞,但是我还是喜欢dfs,要记忆化不然会T     代码 #include <cstdio> #include <cstring> #include <algorithm> using namespace std; const int INF=1<<25; int k,n,m,map[25][25],dx[10]={1,-1,0,0},dy[10]={0,0,1,-1},ans; int vis[25][25][25];…
前言 不说话,先猛戳 Ranklist 看我排名. 这是用 node 自动刷题大概半天的 "战绩",本文就来为大家简单讲解下如何用 node 做一个 "自动AC机". 过程 先来扯扯 oj(online judge).计算机学院的同学应该对 ACM 都不会陌生,ACM 竞赛是拼算法以及数据结构的比赛,而 oj 正是练习 ACM 的 "场地".国内比较有名的 oj 有 poj.zoj 以及 hdoj 等等,这里我选了 hdoj (完全是因为本地上…
Easy Problem from Rujia Liu? Though Rujia Liu usually sets hard problems for contests (for example, regional contests like Xi'an 2006, Beijing 2007 and Wuhan 2009, or UVa OJ contests like Rujia Liu's Presents 1 and 2), he occasionally sets easy probl…
问题:想在某个集合中找出最大或最小的N个元素 解决方案:heapq模块中的nlargest()和nsmallest()两个函数正是我们需要的. >>> import heapq >>> nums=[1,8,2,23,7,-4,18,23,42,37,2] >>> print(heapq.nlargest(3,nums)) [42, 37, 23] >>> print(heapq.nsmallest(3,nums)) [-4, 1, 2…
1.LA 5694 Adding New Machine 关键词:数据结构,线段树,扫描线(FIFO) #include <algorithm> #include <cstdio> #include <cstring> #include <string> #include <queue> #include <map> #include <set> #include <ctime> #include <cm…
题目链接:https://uva.onlinejudge.org/external/15/1599.pdf 题意: 保证在最短路的时候,输出字典序最小的路径. 方法: 路径上有了权值,可以利用图论的数据结构来BFS,很方便. 逆序BFS,找到每个点距离终点的最短路长 d[x] ; 然后,从起点,沿着 d[u] = d[v] + 1; 的路径,分层BFS,选字典序最小的.找到那个最小字典序的节点之后,从新建队列.直到找完 d[0]; #include <bits/stdc++.h> using…
在网上总是查不到很系统的练ACM需要学习的数据结构资料,于是参考看过的东西,自己整理了一份. 能力有限,欢迎大家指正补充. 分类主要参考<算法竞赛入门经典训练指南>(刘汝佳),山东大学数据结构模板 ⊙基本数据结构 1.链表: 块状链表:没练过 Dancing Links:用于优化搜索.解决精确覆盖问题和重复覆盖问题的利器. Knuth教授的始祖论文:Dancing Links中文版 Dancing Links介绍(这篇对DLX的工作过程演示的很详细) DLX——Dancing Links(这篇…