problem 874. Walking Robot Simulation solution1: 思路:1)如何表示移动的方向以及移动的位置坐标; 2)障碍物坐标如何检查;3)求解的是最大距离; class Solution { public: int robotSim(vector<int>& commands, vector<vector<int>>& obstacles) { unordered_set<string> obs; ])…
作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 模拟 日期 题目地址:https://leetcode.com/problems/walking-robot-simulation/description/ 题目描述 A robot on an infinite grid starts at point (0, 0) and faces north. The robot can receive on…
874. Walking Robot Simulation https://www.cnblogs.com/grandyang/p/10800993.html 每走一步(不是没走commands里的一个数字)计算到原点的距离,每走一步都可能遇到障碍物,需要将障碍物的坐标进行存储,以判断是否停止行走. 左转90度,右转90度转换成在x.y的坐标变换上来.左转前进一个index,右转前进一个index,对4取余确保不越界 不知道为什么用unordered_set就编译出错. class Soluti…
A robot on an infinite grid starts at point (0, 0) and faces north.  The robot can receive one of three possible types of commands: -2: turn left 90 degrees -1: turn right 90 degrees 1 <= x <= 9: move forward x units Some of the grid squares are obs…
A robot on an infinite grid starts at point (0, 0) and faces north.  The robot can receive one of three possible types of commands: -2: turn left 90 degrees -1: turn right 90 degrees 1 <= x <= 9: move forward x units Some of the grid squares are obs…
这是悦乐书的第335次更新,第360篇原创 01 看题和准备 今天介绍的是LeetCode算法题中Easy级别的第205题(顺位题号是874).网格上的机器人从点(0,0)开始并朝北.机器人可以接收三种可能类型的命令之一: -2:向左转90度. -1:向右转90度. 1 <= x <= 9:向前移动x个单位. 一些网格方块是障碍物.第i个障碍位于网格点(obstacles[i][0],obstacles[i][1]).如果机器人遇到障碍点,机器人将停留在障碍点前一个网格方格上(但仍然会继续执行…
问题 该文章的最新版本已迁移至个人博客[比特飞],单击链接 https://www.byteflying.com/archives/4038 访问. 机器人在一个无限大小的网格上行走,从点 (0, 0) 处开始出发,面向北方.该机器人可以接收以下三种类型的命令: -2:向左转 90 度 -1:向右转 90 度 1 <= x <= 9:向前移动 x 个单位长度 在网格上有一些格子被视为障碍物. 第 i 个障碍物位于网格点  (obstacles[i][0], obstacles[i][1]) 如…
problem 657. Robot Return to Origin 题意: solution1: class Solution { public: bool judgeCircle(string moves) { , cnt2 = ; for(auto move:moves) { if(move == 'L') cnt1++; else if(move=='R') cnt1--; else if(move=='U') cnt2++; else if(move=='D') cnt2--; }…
A robot on an infinite grid starts at point (0, 0) and faces north.  The robot can receive one of three possible types of commands: -2: turn left 90 degrees -1: turn right 90 degrees 1 <= x <= 9: move forward x units Some of the grid squares are obs…
挺好的一道题目,我的做法是kmp+Dinic网络流.kmp求子串在P中出现的次数,从而计算love值.网络流主要用来处理最优解.case2中p1的love值是8,p2的love值是7,最终T包含p1和p2,hate值也仅仅算一次.这个题目难点在于思考为什么网络流的解法是合理,可以反证.从而导出最优解等于love的总和-最大流.建图方法:source连接p,初始容量为love值:p连接s,初始容量为INF;s连接destination,容量为hate值.在最优解中,如果s到des的流量小于容量,则…