【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和 ...
随机推荐
- Tensorflow细节-P190-输入文件队列
以下代码要学会几个地方 1.filename = ('data.tfrecords-%.5d-of-%.5d' % (i, num_shards)) 这个东西就是要会data.tfrecords-%. ...
- Luogu P3489 [POI2009]WIE-Hexer 最短路
https://www.luogu.org/problemnew/show/P3489 普通的最短路,不过我觉得这个复杂度按道理来说边数不应该是m*2^13吗,不知道是数据比较水还是实际上能证明复杂度 ...
- Subspace Subcode
子码(subcode)的概念来自信息编码,不太容易理解.通常是子域编码(subfield subcode),也可以扩展到子空间编码(subspace subcode). 子空间或者子域编码的一个基本想 ...
- 《挑战30天C++入门极限》C++运算符重载赋值运算符
C++运算符重载赋值运算符 自定义类的赋值运算符重载函数的作用与内置赋值运算符的作用类似,但是要要注意的是,它与拷贝构造函数与析构函数一样,要注意深拷贝浅拷贝的问题,在没有深拷贝浅拷贝的情况下 ...
- golang-结构体的使用
package main import ( "fmt" "unsafe" ) type Person struct { name string sex byte ...
- 第02组 Alpha冲刺(3/6)
第02组 Alpha冲刺(3/6) 队名:無駄無駄组长博客作业博客 组员情况 张越洋 过去两天完成了哪些任务 摸鱼 提交记录(全组共用) 接下来的计划 沟通前后端成员,监督.提醒他们尽快完成各自的 ...
- 对象+String
public class Fruit { public String toString() { return "Fruit toString."; } public static ...
- python反射hasattr getattr setattr delattr
反射 : 是用字符串类型的名字 去操作 变量 相比于用eval('print(name)') 留有 安全隐患 反射 就没有安全问题 hasattr 语法: hasattr(object, name)o ...
- U盘量产过程PS2251-07(PS2307) - F/W 01.05.10 [2014-05-23]
说明本篇文章可能无法解决你的问题,请谨慎尝试.本博客中使用的工具提供下载(如果没有积分,可联系作者免费获取)ChipGenius_v4_00_0030UPTool_v2.089起因 U盘原先正常使用, ...
- Spring中集成Ehcache缓存
1.导入依赖包 <dependency> <groupId>org.springframework</groupId> <artifactId>spri ...