当前位置:网站首页>Sword finger offer 13 Range of motion of robot
Sword finger offer 13 Range of motion of robot
2022-06-29 23:39:00 【anieoo】
Original link : The finger of the sword Offer 13. The range of motion of the robot
solution:
bfs The template questions
class Solution {
public:
typedef pair<int,int> PII;
int dx[4] = {-1, 0, 1, 0},dy[4] = {0, -1, 0, 1};
vector<vector<bool>> sta;
int movingCount(int m, int n, int k) {
if(k == 0) return 1; //k = 0 Only to (0,0)
int ans = 0; // Return value
sta = vector<vector<bool>> (m, vector<bool> (n, false));
queue<PII> que;
que.push({0,0}); // Starting point stack
sta[0][0] = true;
while(!que.empty()) {
auto t = que.front();
que.pop();
ans++;
for(int i = 0;i < 4;i++) {
int x = t.first + dx[i];
int y = t.second + dy[i];
if(x < 0 || x == m || y < 0 || y == n || sta[x][y] || sum(x) + sum(y) > k) continue;
sta[x][y] = true;
que.push({x,y});
}
}
return ans;
}
//sum Function to calculate the sum of each digit
int sum(int x) {
int ans = 0;
while(x) {
ans += x % 10;
x /= 10;
}
return ans;
}
};边栏推荐
- Gracefully transform the SMS business module and start the strategic mode!
- I hope you have no regrets about the regrettable things in the University
- 打造一个 API 快速开发平台,牛逼!
- Become the only key
- Test d'installation du cluster metaq
- FPGA开发(2)——IIC通信
- 股票开户安全吗?上海股票开户。
- 疫情下我离职一年,收入增长了10倍
- 25 interview questions about Apache
- 剑指 Offer 14- I. 剪绳子
猜你喜欢

穿越过后,她说多元宇宙真的存在

Under the epidemic, I left my job for a year, and my income increased 10 times

Paper writing tool: latex online website

CE second operation

AI empowers new retail, the way to win "wisdom" lies in ecological thinking | selected excerpts from digital intelligence night talk live broadcast

CE第二次作业

“微博评论”的高性能高可用计算架构

High performance and high availability computing architecture of "microblog comments" in microblog system
![PROJECT #1 - BUFFER POOL [CMU 15-445645]笔记](/img/33/304e3e78f62b156d0863a41d243679.png)
PROJECT #1 - BUFFER POOL [CMU 15-445645]笔记

Leetcode 1385. 两个数组间的距离值
随机推荐
正则表达式:字符(2)
架构实战营模块5作业
Constexpr function
Leetcode 1385. 两个数组间的距离值
均值、方差、标准差、协方差的概念及意义
Wechat applet: big red festive UI guessing lantern riddles is also called guessing character riddles
shell-运算符
成为唯一的key
海外数字身份验证服务商ADVANCE.AI入选EqualOcean《2022品牌出海服务市场研究报告》
按头安利!好看又实用的电机 SolidWorks模型素材看这里
Implementation principle of dynamic agent
Gracefully transform the SMS business module and start the strategic mode!
Is China Merchants Securities reliable? Is it safe to open a stock account?
Remember the process of checking online MySQL deadlock. You should not only know curd, but also know the principle of locking
搭建企业级NTP时间服务器
LC: maximum subarray and
动态代理的实现原理
软件测试 接口测试 Jmeter 5.5 安装教程
Top ten securities companies: "bulldozer market" reappearance
What is online account opening? In addition, is it safe to open a mobile account?