爱锤键盘的高达奥利给
爱锤键盘的高达奥利给
全部文章
分类
归档
标签
去牛客网
登录
/
注册
爱锤键盘的高达奥利给的博客
全部文章
(共8篇)
题解 | #【模板】二维前缀和#
解法一:暴力解法 每次询问都遍历小矩阵求和,时间复杂度为O(n * m * q),会超时。解法二:前缀和与一维前缀和类似,两步走:第一步:预处理出一个前缀和数组 用dp[i][j]表示从[0][0]位置到[i][j]位置所有元素的和,则有:dp[i][j] = dp[i][j - 1] ...
2023-10-08
0
364
题解 | #【模板】前缀和#
解法一:暴力解法 根据题意,直接进行模拟,每次询问从 l 到 r 进行遍历求和。时间复杂度:O(n * q),会超时解法二:前缀和两步走:第一步:预处理一个前缀和数组 用dp[i]表示从0位置到i位置的元素的和,则遍历数组一次,可以得到一个前缀和数组,前缀和数组中保存了dp[i]的每个数...
2023-10-08
0
334
题解 | #快乐数#
class Solution { public: int nextStep(int cur) { int res = 0; while(cur) { res += (cur % 10) * (cur % 10); ...
2023-08-18
0
401
题解 | #单词识别#
#include <iostream> #include <string> #include <vector> #include <map> #include <utility> #include <algorithm> us...
2023-08-15
0
358
题解 | #二叉搜索树与双向链表#
关键点1:二叉搜索树的中序遍历有序 关键点2:为了进行节点的链接,应引入前一个节点的引用 prev 在中序遍历的过程中对两两节点进行链接 class Solution { public: void InOrder(TreeNode* cur, TreeNode*& pre...
2023-08-11
0
268
题解 | #日期累加# C++
using namespace std; class Date { friend istream& operator>>(istream& cin, Date& d); private: int _year; int _month; int _day;...
2023-05-11
0
255
题解 | #地下迷宫#
思路 本题与(DD3 地下迷宫)相似,在地下迷宫的基础上增加了体力值的限制。 当一个矩阵被确定时,青蛙移动的水平位移已经被确定为矩阵的长度,即青蛙水平移动消耗的体力已经被确定了。所以我们只需要考虑上下方向的移动:上下移动的位移越小,则消耗的体力值越少,所以青蛙的体力消耗主要取决...
2023-01-27
3
696
题解 | #迷宫问题#
#include <iostream> #include <stack> #include <vector> #include <utility> using namespace std; stack<pair<int, int>...
2023-01-26
0
354