装糊涂高手_
装糊涂高手_
全部文章
算法入门基础
题解(28)
归档
标签
去牛客网
登录
/
注册
装糊涂高手_的博客
不懂嵌入式的伪OIer
全部文章
/ 算法入门基础
(共7篇)
题解 | #毒瘤xor#
思路 按位贪心即可,维护一个前缀和统计区间内各数中第i位为1的个数。 代码 #include <bits/stdc++.h> #define ios std::ios::sync_with_stdio(false);std::cin.tie(0) using namespace std;...
贪心
前缀和
2024-01-06
0
238
题解 | #矩阵消除游戏#
思路 枚举行(或列),对列(或行)贪心即可,注意枚举的起点和终点 代码 #include <bits/stdc++.h> #define ios std::ios::sync_with_stdio(false);std::cin.tie(0) using namespace std; ...
枚举
贪心
2024-01-05
0
256
题解 | #[HNOI2003]激光炸弹#
思路 考虑维护一个二维前缀和,每次枚举时仅需枚举炸弹区域的左上角坐标即可, 右下角坐标可通过R得出。 代码 #include <bits/stdc++.h> #define ios std::ios::sync_with_stdio(false);std::cin.tie(0) usin...
枚举
前缀和
2024-01-03
0
308
题解 | #字符串的展开#
考察模拟,从第二个字符开始判断第i个字符是否为减号,为减号且左右侧字符属于字母或数字其中一种时进行展开(这里显然不用将末位字符为减号的情形作单独处理),否则直接添加至结果字符串; 对于展开函数,按题目所给条件模拟即可。 #include <bits/stdc++.h> #define i...
模拟
2023-01-18
0
379
题解 | #牛牛的汉诺塔#
思路 考察递归和记忆化搜索,记忆化搜索忘了咋写,利用同个n的递归移动次数相同的性质可将递归次数减少一半;移动情况以及次数信息由map维护 #include <bits/stdc++.h> #define ios std::ios::sync_with_stdio(false);std::...
递归
记忆化搜索
2023-01-07
1
411
题解 | #牛牛与后缀表达式#
思路 考察递归,遇到操作数入栈,遇到运算符将栈顶前两个元素出栈运算,再将结果入栈,遍历完后栈顶元素即表达式结果 class Solution { public: /** * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 * * 给定一...
栈
递归
2023-01-07
1
352
题解 | #N皇后问题#
思路 考察递归,枚举皇后的位置,不符合条件回溯即可 #include <bits/stdc++.h> #define ios std::ios::sync_with_stdio(false);std::cin.tie(0) using namespace std; int res[20]...
回溯
递归
2023-01-07
0
282