【Leetcode_easy】874. Walking Robot Simulation
problem
solution1:
思路:1)如何表示移动的方向以及移动的位置坐标; 2)障碍物坐标如何检查;3)求解的是最大距离;
class Solution {
public:
int robotSim(vector<int>& commands, vector<vector<int>>& obstacles) {
unordered_set<string> obs;
for(auto a:obstacles) obs.insert(to_string(a[]) + "-"+to_string(a[]));
//int[][] dirs = new int[][]{{0, 1}, {1, 0}, {0, -1}, {-1, 0}};
vector<int> dirX = {, , , -};
vector<int> dirY = {, , -, };
int res = , id = , x = , y = ;
for(auto cmd:commands)
{
if(cmd==-) id = (id+) % ;
else if(cmd==-) id = (id-+) % ;
else
{
while(cmd--> && !obs.count(to_string(x+dirX[id])+"-"+to_string(y+dirY[id])))
{
//cmd--;
x += dirX[id];
y += dirY[id];
}
}
res = max(res, x*x+y*y);
}
return res;
}
};
参考
1. Leetcode_easy_874. Walking Robot Simulation;
2. grandyang;
3. discuss;
完
【Leetcode_easy】874. Walking Robot Simulation的更多相关文章
- 【LeetCode】874. Walking Robot Simulation 解题报告(Python & C++)
作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 模拟 日期 题目地址:https://leetcod ...
- leetcode 874. Walking Robot Simulation
874. Walking Robot Simulation https://www.cnblogs.com/grandyang/p/10800993.html 每走一步(不是没走commands里的一 ...
- [LeetCode] 874. Walking Robot Simulation 走路机器人仿真
A robot on an infinite grid starts at point (0, 0) and faces north. The robot can receive one of th ...
- 874. Walking Robot Simulation
A robot on an infinite grid starts at point (0, 0) and faces north. The robot can receive one of th ...
- LeetCode.874-走路机器人模拟(Walking Robot Simulation)
这是悦乐书的第335次更新,第360篇原创 01 看题和准备 今天介绍的是LeetCode算法题中Easy级别的第205题(顺位题号是874).网格上的机器人从点(0,0)开始并朝北.机器人可以接收三 ...
- C#LeetCode刷题之#874-模拟行走机器人(Walking Robot Simulation)
问题 该文章的最新版本已迁移至个人博客[比特飞],单击链接 https://www.byteflying.com/archives/4038 访问. 机器人在一个无限大小的网格上行走,从点 (0, 0 ...
- 【Leetcode_easy】657. Robot Return to Origin
problem 657. Robot Return to Origin 题意: solution1: class Solution { public: bool judgeCircle(string ...
- [Swift]LeetCode874. 模拟行走机器人 | Walking Robot Simulation
A robot on an infinite grid starts at point (0, 0) and faces north. The robot can receive one of th ...
- 【HDOJ】3505 Writing Robot
挺好的一道题目,我的做法是kmp+Dinic网络流.kmp求子串在P中出现的次数,从而计算love值.网络流主要用来处理最优解.case2中p1的love值是8,p2的love值是7,最终T包含p1和 ...
随机推荐
- 第4课.vi编辑器
1.vi编辑器的配置 cd /etc/vim cp vimrc ~/.vimrc cd ~ gedit .vimrc 在.vimrc中加入如下内容: "关闭兼容功能 set nocompat ...
- HTML插入音频和视频:audio和video标签及其属性
一.上传到第三方网站,然后引入例如视频上传到优酷网,然后得到代码 <iframe height=498 width=510 src='http://player.youku.com/embed/ ...
- 9.11 myl模拟赛
9.11 myl 模拟赛 100 + 100 + 0 第一题耗费了太多的时间,导致最后一题没有时间想,直接去写了暴力,而且出题人没有给暴力分.... Problem 1. superman [题目描述 ...
- lixuxmint系统定制与配置(4)-应用安装
小书匠Linux 先简单列一下,其实每个软件都有自己的个性化配置,以后有时间了,逐个记录下来.编程主力环境是Python,编辑器使用Jupyter,这个编辑器是在远程服务器启动,映射端口到本地来编辑. ...
- js 中的方法注入(aop)
js 中的方法注入 java中很多框架支持 apo 的注入, js中也可以类似的进行实现 主要是通过扩展js中方法的老祖 Function 对象来进行实现. Function.prototype.af ...
- Linux 文件系统引起的云盘文件系统异常导致 MySQL 数据页损坏事故恢复复盘
事故的起因是因为当我访问某个数据库的某个表的时候,MySQL 立即出现崩溃并且去查看 MySQL 的错误日志出现类似信息 --09T05::.232564Z [ERROR] InnoDB: Space ...
- layui select多选下拉显示 以及回显
<input type="hidden" id="hiddensheshi" name="hiddensheshi" value=&q ...
- [Shell]MySql慢查询日志GetShell
通过开启慢查询日志,配置可解析日志文件GETSHELL. MySQL的慢查询日志是MySQL提供的一种日志记录,它用来记录在MySQL中响应时间超过阀值的语句. long_query_time的默认值 ...
- python 通过下载包setup.py安装模块
下载安装包,并解压到相应的位置 1.打开cmd 2.到达安装目录 3.python setup.py build 4.python setup.py install
- 【转】Python编程: 多个PDF文件合并以及网页上自动下载PDF文件
1. 多个PDF文件合并1.1 需求描述有时候,我们下载了多个PDF文件, 但希望能把它们合并成一个PDF文件.例如:你下载的数个PDF文件资料或者电子发票,你可以使用python程序合并成一个PDF ...