随笔分类 -  数据结构与算法

摘要:首先定义一个二叉树的结构体 struct BinaryTree { int value; BinaryTree* lson; BinaryTree* rson; }; 第一种方法 int maxOf(BinaryTree* root) { if (root->rson) { return maxOf 阅读全文
posted @ 2019-01-09 15:01 Jathon-cnblogs 阅读(2231) 评论(0) 推荐(0)
摘要:这个Trie原先用C++就敲得很熟了,看了蓝桥杯的视频后学会把一个功能这样封装起来,以后用的时候就很爽可以直接调用了,所以就用Java写了; public class Trie { private final int SIZE = 26; private final int HEAD = 'a'; 阅读全文
posted @ 2019-01-09 13:01 Jathon-cnblogs 阅读(306) 评论(0) 推荐(0)
摘要:构建一个值的类型为int的平衡二叉搜索树,输入N,然后进行N次插入操作,每次插入之后进行一次遍历验证代码正确性。(删除目前还写不出来,以后有机会再补吧) #include "bits/stdc++.h" using namespace std; typedef long long LL; const 阅读全文
posted @ 2019-01-08 21:40 Jathon-cnblogs 阅读(329) 评论(0) 推荐(0)
摘要:这题在比赛的时候耗了我近两个小时,还是没做出来。用到逆元和期望。赛前掌握的不够好,现在看了几位大佬的代码之后把这题补上。 代码参考来源:https://blog.csdn.net/qq_36797743/article/details/85834812 1097D - 20 GNU C++11 Ha 阅读全文
posted @ 2019-01-06 13:31 Jathon-cnblogs 阅读(145) 评论(0) 推荐(0)
摘要:输入N个数,找每个数的前驱和后继。如果没有前驱或后继,输出-1; 思路: 如果有右子树,则右子树的最小值为当前节点的后继;否则后继为当前节点往祖先搜索,第一次是左孩子的节点的父亲的值; 如果有左子树,则左子树的最大值为当前节点的前驱;否则前驱为当前节点往祖先搜索,第一次是右孩子的节点的父亲的值; # 阅读全文
posted @ 2019-01-04 21:46 Jathon-cnblogs 阅读(803) 评论(0) 推荐(0)
摘要:构建一个值的类型为int的二叉搜索树,输入N和M,然后进行N次插入操作,每次插入之后进行一次遍历验证代码正确性。然后进行M次删除操作,每次删除之后进行一次遍历验证代码正确性。 #include "bits/stdc++.h" using namespace std; typedef long lon 阅读全文
posted @ 2019-01-04 16:09 Jathon-cnblogs 阅读(718) 评论(0) 推荐(0)
摘要:实现一个键的类型为int,值的类型为int的HashMap 输入一个T,表示操作次数; 之后每行接一个操作,可以包括插入、删除、修改、查询、清空、判断是否有这个键; 因为是刚学完随手敲的,所以功能粗糙。插入不考虑键已经存在的情况。删除、修改、查询不考虑键不存在的情况; #include "bits/ 阅读全文
posted @ 2019-01-01 14:12 Jathon-cnblogs 阅读(465) 评论(0) 推荐(0)
摘要:用两个指针,一个快指针一次走两步,一个慢指针一次走一步。快慢指针可以重合表示链表有环,此时距离环起点的距离和起点距离环起点的距离相等。 #include "bits/stdc++.h" using namespace std; struct List { List* next; }; List* b 阅读全文
posted @ 2018-12-30 15:02 Jathon-cnblogs 阅读(190) 评论(0) 推荐(0)
摘要:肥宅快乐数 Time limit:1s Memory limit:128M Description 作为一个肥宅,栗酱每天都从不同的事物上获得快乐。今天他发现每一个形如 (i,j) 的二元组当满足 “i + j == i | j” 时都会给他带来1点快乐。现在问题来了,[1, 2^k] 以内的正整数 阅读全文
posted @ 2018-11-27 21:03 Jathon-cnblogs 阅读(283) 评论(0) 推荐(0)
摘要:这题比较方便的解法是使用STL里的map和set代码如下: #include"bits/stdc++.h" using namespace std; map<string,set<string> >mp; string s,t; int main(){ while(cin>>s&&(s!="XXXX 阅读全文
posted @ 2018-11-25 20:42 Jathon-cnblogs 阅读(211) 评论(0) 推荐(0)
摘要:map map可以理解为一个数组(但实质上并不是,只是方便理解),我们一般的数组不管定义成什么类型他的下标都是整型(int),map和这些数组的区别是他的下标可以是其他类型,由自己定义。map的创建、插值和访问示例如下: #include"cstdio"#include"string" #inclu 阅读全文
posted @ 2018-11-20 19:36 Jathon-cnblogs 阅读(186) 评论(1) 推荐(0)
摘要:线段树(kuangbin本题链接) #include "bits/stdc++.h" using namespace std; const int MAXN = 50010; struct Node { int l, r; int sum; } segTree[MAXN * 4]; void bui 阅读全文
posted @ 2018-11-19 22:31 Jathon-cnblogs 阅读(202) 评论(0) 推荐(1)
摘要:矩阵快速幂 #include"bits/stdc++.h" using namespace std; const int mod = 9973; int n, k; struct Mat { int mat[11][11]; Mat() { memset(mat, 0, sizeof(mat)); 阅读全文
posted @ 2018-11-03 17:08 Jathon-cnblogs 阅读(204) 评论(0) 推荐(0)
摘要:这题就是从1到n点进行遍历,对未加热的点找到最远的能加热到这个点的点,还是看代码讲吧 #include"bits/stdc++.h" using namespace std; const int inf=0x3f3f3f3f; typedef long long LL; int a[1005],an 阅读全文
posted @ 2018-10-14 19:28 Jathon-cnblogs 阅读(352) 评论(0) 推荐(0)
摘要:#include"bits/stdc++.h" using namespace std; struct tree{ tree* Next[26]; int cnt; }*root; tree* init(){ tree* t=(tree*)malloc(sizeof(tree)); memset(t 阅读全文
posted @ 2018-10-02 22:08 Jathon-cnblogs 阅读(153) 评论(0) 推荐(0)
摘要:由于这道题目数据范围小,所以属于水题。可以采取暴力的做法来解决。 代码如下: #include"bits/stdc++.h" using namespace std; const int maxn=65535; bool tag[maxn+5]; vector<int>v;int n; bool j 阅读全文
posted @ 2018-09-24 22:13 Jathon-cnblogs 阅读(301) 评论(0) 推荐(0)
摘要:迪杰斯特拉算法--O(n^2) #include"iostream" #include"cstring" #include"cstdio" using namespace std; const int inf = 0x3f3f3f3f; typedef long long LL; int map[1 阅读全文
posted @ 2018-09-20 21:20 Jathon-cnblogs 阅读(429) 评论(0) 推荐(0)
摘要:快速幂(本代码中的^表示次幂不是异或) Accepted 1061 0MS 1368K 679 B G++ #include "bits/stdc++.h" using namespace std; const int MOD = 10; int quick_pow(int n, int m) { 阅读全文
posted @ 2018-09-20 16:33 Jathon-cnblogs 阅读(106) 评论(0) 推荐(0)
摘要:字典树解法(Trie树) Accepted 1251 156MS 45400K 949 B C++ #include"iostream" #include"cstdlib" #include"cstring" #include"cstdio" using namespace std; struct 阅读全文
posted @ 2018-09-19 20:28 Jathon-cnblogs 阅读(177) 评论(0) 推荐(0)