【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和 ...
随机推荐
- django 第五天 自定义标签 静态文件
昨日忘记上传,先预留位置,稍后补上
- Oracle Replace()函数与translate()函数 替换函数
简要比较: replace 字符串级别的代替 如:SELECT REPLACE('accd','cd','ef') from dual; --> aefd translate 字符级别的代替 如 ...
- (尚011)Vue事件处理
test011.html <!DOCTYPE html><html lang="en"><head> <meta charset=&quo ...
- mysql 5.7 增删改查及别名的用法
1.启动和停止服务 一)启动和停止 #启动服务: $sudo service mysql start #停止服务: $sudo service mysql stop 二)创建和选择数据库 [创建数据库 ...
- PHP安装之configure的配置参数
1.生成环境安装配置如下 要求安装如下库: imagickgdmysqlmysqlimysqlndphalconPharsoapsocketsxwebxsvczipzlib 具体查看 vim php- ...
- 浅谈bitset
维护二进制的数据结构,常数可近似看作\(\frac{1}{32}\) 定义 bitset<4> bitset1; 长度为4,下标[0,3],默认为0 bitset<4> bit ...
- lisp语法分析与执行分离
lisp语法分析与执行分离 <sicp>4.1.7节读书笔记 这节中将书中之前实现的解释器做了改进,将语法分析于执行分离.这样做能提高很多效率,比如我们需定义一个过程,然后执行该过程多次. ...
- c#传不确定的参数个数,比如int型
a(params int[] ) 调用时a(1,2,3,4,5,6)
- Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sqlSessionFactory' defined in class path resource [spring-mybatis.xml]: Initialization of bean failed
- java项目代码上线
java项目代码上线 1:java项目代码上线架构图 ip地址及主机名规划 10.0.0.11 deploy 10.0.0.12 tomcat-web01 10.0.0.13 git.oldboy ...