![](https://img-blog.csdnimg.cn/20201014180756738.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
刷题代码
Catherine-lisa
这个作者很懒,什么都没留下…
展开
-
洛谷P1030求先序排列
在这里做个小总结吧:对于树的三种遍历如果给定前序遍历和后序遍历,中序遍历不一定是确定的;但是给定中序与后序排列,是可以确定前序的;并且给定前序和中序也是可以确定后序的。这道题就讨论第二种情况:重点就是先找到根,然后在递归就可以了~#define _CRT_SECURE_NO_WARNINGS#include <cstdio>#include <cmath>#include <iostream>#include <algorithm>#i原创 2020-09-25 11:23:00 · 155 阅读 · 0 评论 -
洛谷P3884 二叉树问题的纯代码题解
好久没有发题解了,有没有人想我呀~(其实没有主要是最近开学啦,我变成大二啦,校园里来了好多学弟学妹,各种课程和活动一下子就把日程给塞满了,弄得我都没有大块的专门的时间写题,现在在数据结构的课上摸鱼~不废话了,这个题关键点就是储存一下father的点,再记录一下深度和宽度就可以了~上代码:#define _CRT_SECURE_NO_WARNINGS#include <cstdio>#include <cmath>#include <iostream>#inc原创 2020-09-25 11:20:44 · 341 阅读 · 0 评论 -
洛谷P4387验证栈序列的纯代码题解
纪念一下在上课的时候摸鱼过了这道题还嚣张地在这写博客哈哈哈其实没过(如果没看题解的话这道题的基本思路就是用栈模拟就好了但是还是有一点点收获的(我绝对不是想喝一点点了因为要对两列数字进行比较,我一开始想的是双指针法,用了loca和locb同时对两个数列进行遍历,但是这样思路容易乱,我这么写不知道哪里错了但我就是WA了;后来一参考题解的写法发现,与其两个同时都要移动指针,不如固定一个去移动另一个,所以对a遍历就行了,在遍历的时候顺带和b比较注意一个细节,可以一次性出栈多个数字,所以这个位置用的是wh原创 2020-09-18 10:33:32 · 228 阅读 · 0 评论 -
洛谷P2404 自然数的拆分的纯代码题解
我一开始以为是个记忆化搜素,然后觉得哇这样的记忆化怎么存呢后来发现是个打表题(bushi#define _CRT_SECURE_NO_WARNINGS#include <cstdio>#include <iostream>#include <algorithm>#include <cstring>const int N = 1e3 + 5;using namespace std;int a[N] = { 1 };int n;void se原创 2020-09-02 10:07:58 · 149 阅读 · 0 评论 -
洛谷P1135 奇怪的电梯的纯代码题解
没啥特殊的,记住队列里存的是什么就行,直接上代码#include <iostream>#include <cstdio>#include <queue>#include <cstring>#define MAXN 205using namespace std;queue <int> q;int n, a, b;int k[MAXN], mark[MAXN], ans[MAXN];int main(){ scanf(原创 2020-08-06 16:19:11 · 251 阅读 · 1 评论 -
洛谷P1443 马的遍历的纯代码题解
之前的二分题解就全部告一段落啦!现在来看搜索而马的遍历是一道非常典型的bfs,这里用队列来实现比较方便#include <iostream>#include <cstdio>#include <cstring>#include <queue>#define MAXN 405using namespace std;typedef struct coordinate{ int x, y;}coor;coor horse;queue &原创 2020-08-06 15:37:06 · 205 阅读 · 1 评论 -
洛谷P2392 考前抱佛脚的纯代码题解
一个简单的dfs,搜索的层数为题目数#include <iostream>#include <cstdio>#include <cstring>using namespace std;int maxn, ans, sum;int s[5], a[25];void dfs(int time, int cengshu, int i){ if(cengshu > s[i]) { maxn = max(maxn, time原创 2020-08-06 14:48:57 · 280 阅读 · 0 评论 -
洛谷P2240 木材加工的纯代码题解
和P1873 砍树那一题基本没有区别照这样子写就是了写了几题发现其实二分能变化的形势并不多…板子基本就是死的,在更复杂的题目中更多的是作为查找的一种有效方式出现#include <iostream>#include <cstdio>using namespace std;int n, k, ans;int a[100005];bool judge(int x){ int tot = 0; if(x == 0) return true; fo原创 2020-08-02 18:19:52 · 198 阅读 · 0 评论 -
洛谷P1024 一元三次方程的纯代码题解
一个入门题第一下给我WA掉了不愧是我一检查发现是函数传double参数时习惯性写成了int我原地嘤嘤嘤这题,注意精度,没了#include <iostream>#include <cstdio>#include <algorithm>#include <cmath>using namespace std;#define eps 1e-4double a, b, c, d;double f(double x){ return原创 2020-08-02 18:16:28 · 181 阅读 · 0 评论 -
洛谷P1824 进击的奶牛的纯代码题解
今天是二分专题~说白了就是一种在有序的条件下高效的枚举方法。本题想让奶牛间间距尽可能大,就二分找呗,如果可行就先存着,往大了方向找,看有没有更好的答案,反之就往小的方向找#include <iostream>#include <cstdio>#include <algorithm>using namespace std;int n, c, l, r, mid, ans;int a[100005];bool judge(int x){ int原创 2020-08-02 18:13:15 · 468 阅读 · 1 评论 -
洛谷P2249 查找的纯代码题解
最基本的一个二分没了注意细节叭,l和r是<还是<=的关系,然后转换边界的时候注意要不要加一,否则会死循环#include <iostream>#include <cstdio>using namespace std;//#define MAXN 1e6+5int m, n, q, loc;int a[1000005];int binary_search(){ int l = 1; int r = n; int mid;原创 2020-08-01 17:21:38 · 830 阅读 · 0 评论 -
洛谷P4447 分组的纯代码题解
洛谷上面有很多大佬的讲解,在这我就不赘述了,大致的思路就是为了让最少的尽量多,那么分得就要尽可能地平均,对一个能同时接在几组后面的数字,就接在最短的一组里。#include <iostream>#include <cstdio>#include <algorithm>using namespace std;#define MAXN 100005int n, zushu, minn;int a[MAXN], nnext[MAXN], size[MAXN];原创 2020-08-01 17:19:30 · 465 阅读 · 0 评论 -
洛谷P3817 小A的糖果 纯代码题解
就是一个局部的贪心,题目很水,但是我一开始愣是没反应过来是我太菜 菜是原罪#include <iostream>#include <cstdio>using namespace std;int n, x, front, now;long long ans;int main(){ scanf("%d%d%d", &n, &x, &front); for(int i = 2; i <= n; i ++) {原创 2020-08-01 17:13:18 · 218 阅读 · 0 评论